<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
</head>
<body>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">You can influence what name the relationships and tables have with a map,</p>
<p dir="auto">see: <a href="https://metacpan.org/pod/DBIx::Class::Schema::Loader::Base#moniker_map">https://metacpan.org/pod/DBIx::Class::Schema::Loader::Base#moniker_map</a></p>
<p dir="auto">Me preference is to use a <code>dbic-conf.pl</code> config file with all of the options.</p>
<p dir="auto">Best,</p>
<p dir="auto">On 11 Feb 2021, at 6:45, Dave Cross wrote:</p>
</div><div style="white-space:normal"><blockquote style="border-left:2px solid #5855D5; color:#5855D5; margin:0 0 5px; padding-left:5px"><p dir="auto">I have a database that contains tasks and the dependencies between
<br>
those tasks. It contains two tables:
<br>
CREATE TABLE `task` (
<br>
  `id` int(11) NOT NULL,
<br>
  `done` tinyint(1) DEFAULT NULL,
<br>
  `title` char(100) DEFAULT NULL,
<br>
  PRIMARY KEY (`id`)
<br>
)
<br>
CREATE TABLE `task_dependency` (
<br>
  `id` int(11) NOT NULL,
<br>
  `previous_task_id` int(11) NOT NULL,
<br>
  `next_task_id` int(11) NOT NULL,
<br>
  PRIMARY KEY (`id`),
<br>
  KEY `previous_task_id` (`previous_task_id`),
<br>
  KEY `next_task_id` (`next_task_id`),
<br>
  CONSTRAINT `task_dependency_ibfk_1` FOREIGN KEY (`previous_task_id`)
<br>
REFERENCES `task` (`id`),
<br>
  CONSTRAINT `task_dependency_ibfk_2` FOREIGN KEY (`next_task_id`)
<br>
REFERENCES `task` (`id`)
<br>
)
<br>
You'll see there are two foreign keys between task_dependency and
<br>
task. Other than the names, these columns are defined in exactly the
<br>
same way.
<br>
But when I use dbicdump to generate DBIC classes for these tables,
<br>
there's a subtle difference in the way the relationships are named. In
<br>
Task::Schema::Result::Task, I get the following relationships.
<br>
=head1 RELATIONS
<br>
=head2 task_dependencies_next_task
<br>
Type: has_many
<br>
Related object: L&lt;Task::Schema::Result::TaskDependency&gt;
<br>
=cut
<br>
__PACKAGE__-&gt;has_many(
<br>
  "task_dependencies_next_task",
<br>
  "Task::Schema::Result::TaskDependency",
<br>
  { "foreign.next_task_id" =&gt; "self.id" },
<br>
  { cascade_copy =&gt; 0, cascade_delete =&gt; 0 },
<br>
);
<br>
=head2 task_dependency_previous_tasks
<br>
Type: has_many
<br>
Related object: L&lt;Task::Schema::Result::TaskDependency&gt;
<br>
=cut
<br>
__PACKAGE__-&gt;has_many(
<br>
  "task_dependency_previous_tasks",
<br>
  "Task::Schema::Result::TaskDependency",
<br>
  { "foreign.previous_task_id" =&gt; "self.id" },
<br>
  { cascade_copy =&gt; 0, cascade_delete =&gt; 0 },
<br>
);
<br>
Note that the plurals are in different places in the relationship names.
<br>
task_dependencIES_next_task vs task_dependency_previous_taskS
<br>
If it matters, this is a MariaDB database. And here's the config file
<br>
I used with dbicdump:
<br>
schema_class Task::Schema
<br>
&lt;connect_info&gt;
<br>
  dsn   dbi:mysql:dbname=test;hostname=172.17.128.1
<br>
  user  test
<br>
  pass  test
<br>
&lt;/connect_info&gt;
<br>
&lt;loader_options&gt;
<br>
  dump_directory        ./Testlib
<br>
  allow_extra_m2m_cols  1
<br>
&lt;/loader_options&gt;
<br>
I'm using DBIx::Class::Schema::Loader version 0.07049.
<br>
This isn't a major problem, but I just know that I'll keep typing
<br>
these names incorrectly :-/
<br>
Is there anything I can do to fix this? Or is it expected behaviour?
<br>
Cheers,
<br>
Dave...
<br>
_______________________________________________
<br>
List: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</a>
<br>
IRC: irc.perl.org#dbix-class
<br>
SVN: <a href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/">http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</a>
<br>
Searchable Archive: <a href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk">http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk</a>
</p>
</blockquote></div>
<div style="white-space:normal">

</div></div>
</body>
</html>