Re: [Dbix-class] Differences in generated relationships
On Fri, 12 Feb 2021 at 08:47, Matthew Somerville wrote: > > On Thu, 11 Feb 2021 at 16:12, Dave Cross wrote: > > But I'd still like to know where those differences were coming from. > > In DBIx::Class::Schema::Loader::RelBuilder, in the > _relnames_and_method function, there is a "If more than one rel > between this pair of tables" section. Not sure I understand it fully, > but it looks like it does do something different the first time a > relation is added (when it looks like it pluralizes the column name), > as opposed to the second time when the temporary file is read in and > then might not do so. Interesting. Thanks, I'll have a look there. Cheers, Dave... ___ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
Re: [Dbix-class] Differences in generated relationships
On Thu, 11 Feb 2021 at 16:12, Dave Cross wrote: > But I'd still like to know where those differences were coming from. In DBIx::Class::Schema::Loader::RelBuilder, in the _relnames_and_method function, there is a "If more than one rel between this pair of tables" section. Not sure I understand it fully, but it looks like it does do something different the first time a relation is added (when it looks like it pluralizes the column name), as opposed to the second time when the temporary file is read in and then might not do so. ATB, Matthew ___ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
Re: [Dbix-class] Differences in generated relationships
Thanks, yes, I've done that now. I've also changed the definition of the task_dependency table so that it's a proper linking table and therefore dbicdump generates many to many relationships for it - which means I'm far less likely to use the misnamed relationships. But I'd still like to know where those differences were coming from. Cheers, Dave... On Thu, 11 Feb 2021 at 15:52, Francisco Obispo wrote: > > You can influence what name the relationships and tables have with a map, > > see: https://metacpan.org/pod/DBIx::Class::Schema::Loader::Base#moniker_map > > Me preference is to use a dbic-conf.pl config file with all of the options. > > Best, > > On 11 Feb 2021, at 6:45, Dave Cross wrote: > > I have a database that contains tasks and the dependencies between > those tasks. It contains two tables: > CREATE TABLE `task` ( > `id` int(11) NOT NULL, > `done` tinyint(1) DEFAULT NULL, > `title` char(100) DEFAULT NULL, > PRIMARY KEY (`id`) > ) > CREATE TABLE `task_dependency` ( > `id` int(11) NOT NULL, > `previous_task_id` int(11) NOT NULL, > `next_task_id` int(11) NOT NULL, > PRIMARY KEY (`id`), > KEY `previous_task_id` (`previous_task_id`), > KEY `next_task_id` (`next_task_id`), > CONSTRAINT `task_dependency_ibfk_1` FOREIGN KEY (`previous_task_id`) > REFERENCES `task` (`id`), > CONSTRAINT `task_dependency_ibfk_2` FOREIGN KEY (`next_task_id`) > REFERENCES `task` (`id`) > ) > You'll see there are two foreign keys between task_dependency and > task. Other than the names, these columns are defined in exactly the > same way. > But when I use dbicdump to generate DBIC classes for these tables, > there's a subtle difference in the way the relationships are named. In > Task::Schema::Result::Task, I get the following relationships. > =head1 RELATIONS > =head2 task_dependencies_next_task > Type: has_many > Related object: L > =cut > __PACKAGE__->has_many( > "task_dependencies_next_task", > "Task::Schema::Result::TaskDependency", > { "foreign.next_task_id" => "self.id" }, > { cascade_copy => 0, cascade_delete => 0 }, > ); > =head2 task_dependency_previous_tasks > Type: has_many > Related object: L > =cut > __PACKAGE__->has_many( > "task_dependency_previous_tasks", > "Task::Schema::Result::TaskDependency", > { "foreign.previous_task_id" => "self.id" }, > { cascade_copy => 0, cascade_delete => 0 }, > ); > Note that the plurals are in different places in the relationship names. > task_dependencIES_next_task vs task_dependency_previous_taskS > If it matters, this is a MariaDB database. And here's the config file > I used with dbicdump: > schema_class Task::Schema > > dsn dbi:mysql:dbname=test;hostname=172.17.128.1 > user test > pass test > > > dump_directory ./Testlib > allow_extra_m2m_cols 1 > > I'm using DBIx::Class::Schema::Loader version 0.07049. > This isn't a major problem, but I just know that I'll keep typing > these names incorrectly :-/ > Is there anything I can do to fix this? Or is it expected behaviour? > Cheers, > Dave... > ___ > List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class > IRC: irc.perl.org#dbix-class > SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ > Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk > > ___ > List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class > IRC: irc.perl.org#dbix-class > SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ > Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk ___ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
Re: [Dbix-class] Differences in generated relationships
You can influence what name the relationships and tables have with a map, see: https://metacpan.org/pod/DBIx::Class::Schema::Loader::Base#moniker_map Me preference is to use a `dbic-conf.pl` config file with all of the options. Best, On 11 Feb 2021, at 6:45, Dave Cross wrote: I have a database that contains tasks and the dependencies between those tasks. It contains two tables: CREATE TABLE `task` ( `id` int(11) NOT NULL, `done` tinyint(1) DEFAULT NULL, `title` char(100) DEFAULT NULL, PRIMARY KEY (`id`) ) CREATE TABLE `task_dependency` ( `id` int(11) NOT NULL, `previous_task_id` int(11) NOT NULL, `next_task_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `previous_task_id` (`previous_task_id`), KEY `next_task_id` (`next_task_id`), CONSTRAINT `task_dependency_ibfk_1` FOREIGN KEY (`previous_task_id`) REFERENCES `task` (`id`), CONSTRAINT `task_dependency_ibfk_2` FOREIGN KEY (`next_task_id`) REFERENCES `task` (`id`) ) You'll see there are two foreign keys between task_dependency and task. Other than the names, these columns are defined in exactly the same way. But when I use dbicdump to generate DBIC classes for these tables, there's a subtle difference in the way the relationships are named. In Task::Schema::Result::Task, I get the following relationships. =head1 RELATIONS =head2 task_dependencies_next_task Type: has_many Related object: L =cut __PACKAGE__->has_many( "task_dependencies_next_task", "Task::Schema::Result::TaskDependency", { "foreign.next_task_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); =head2 task_dependency_previous_tasks Type: has_many Related object: L =cut __PACKAGE__->has_many( "task_dependency_previous_tasks", "Task::Schema::Result::TaskDependency", { "foreign.previous_task_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); Note that the plurals are in different places in the relationship names. task_dependencIES_next_task vs task_dependency_previous_taskS If it matters, this is a MariaDB database. And here's the config file I used with dbicdump: schema_class Task::Schema dsn dbi:mysql:dbname=test;hostname=172.17.128.1 user test pass test dump_directory./Testlib allow_extra_m2m_cols 1 I'm using DBIx::Class::Schema::Loader version 0.07049. This isn't a major problem, but I just know that I'll keep typing these names incorrectly :-/ Is there anything I can do to fix this? Or is it expected behaviour? Cheers, Dave... ___ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk ___ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
[Dbix-class] Differences in generated relationships
I have a database that contains tasks and the dependencies between those tasks. It contains two tables: CREATE TABLE `task` ( `id` int(11) NOT NULL, `done` tinyint(1) DEFAULT NULL, `title` char(100) DEFAULT NULL, PRIMARY KEY (`id`) ) CREATE TABLE `task_dependency` ( `id` int(11) NOT NULL, `previous_task_id` int(11) NOT NULL, `next_task_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `previous_task_id` (`previous_task_id`), KEY `next_task_id` (`next_task_id`), CONSTRAINT `task_dependency_ibfk_1` FOREIGN KEY (`previous_task_id`) REFERENCES `task` (`id`), CONSTRAINT `task_dependency_ibfk_2` FOREIGN KEY (`next_task_id`) REFERENCES `task` (`id`) ) You'll see there are two foreign keys between task_dependency and task. Other than the names, these columns are defined in exactly the same way. But when I use dbicdump to generate DBIC classes for these tables, there's a subtle difference in the way the relationships are named. In Task::Schema::Result::Task, I get the following relationships. =head1 RELATIONS =head2 task_dependencies_next_task Type: has_many Related object: L =cut __PACKAGE__->has_many( "task_dependencies_next_task", "Task::Schema::Result::TaskDependency", { "foreign.next_task_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); =head2 task_dependency_previous_tasks Type: has_many Related object: L =cut __PACKAGE__->has_many( "task_dependency_previous_tasks", "Task::Schema::Result::TaskDependency", { "foreign.previous_task_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); Note that the plurals are in different places in the relationship names. task_dependencIES_next_task vs task_dependency_previous_taskS If it matters, this is a MariaDB database. And here's the config file I used with dbicdump: schema_class Task::Schema dsn dbi:mysql:dbname=test;hostname=172.17.128.1 user test pass test dump_directory./Testlib allow_extra_m2m_cols 1 I'm using DBIx::Class::Schema::Loader version 0.07049. This isn't a major problem, but I just know that I'll keep typing these names incorrectly :-/ Is there anything I can do to fix this? Or is it expected behaviour? Cheers, Dave... ___ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk