From: Dagfinn Ilmari Mannsåker Date: Tue, 6 Aug 2013 21:57:04 +0000 (+0100) Subject: Fix many_to_many bridges involving might_have relationships X-Git-Tag: 0.07036_01~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b0cdc8a5bc6db9206a53e52bd9c868ba8442ca2b;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Fix many_to_many bridges involving might_have relationships --- diff --git a/Changes b/Changes index b746835..741efb3 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader - Fix typos in POD and comments (RT#87644) - Don't ship MYMETA.* files (RT#87713) + - Fix many_to_many bridges involving might_have relationships 0.07036 2013-07-08 - Fix stray comma in Pg on_delete/on_update => CASCADE (RT#84706) diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index c5f213a..710ea54 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -514,13 +514,13 @@ sub _generate_m2ms { my $class2 = $rels->[1]{args}[1]; my $class1_to_link_table_rel = first { - $_->{method} eq 'has_many' && $_->{args}[1] eq $class + $_->{method} =~ /\A(?:has_many|might_have)\z/ && $_->{args}[1] eq $class } @{ $all_code->{$class1} }; my $class1_to_link_table_rel_name = $class1_to_link_table_rel->{args}[0]; my $class2_to_link_table_rel = first { - $_->{method} eq 'has_many' && $_->{args}[1] eq $class + $_->{method} =~ /\A(?:has_many|might_have)\z/ && $_->{args}[1] eq $class } @{ $all_code->{$class2} }; my $class2_to_link_table_rel_name = $class2_to_link_table_rel->{args}[0]; diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 8b174d0..92dda03 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -927,12 +927,12 @@ qr/\n__PACKAGE__->(?:belongs_to|has_many|might_have|has_one|many_to_many)\( ok($m2m = (try { $class18->_m2m_metadata->{children} }), 'many_to_many created'); - is $m2m->{relation}, 'loader_test20s', 'm2m near rel'; + is $m2m->{relation}, 'loader_test20s', 'm2m near has_many rel'; is $m2m->{foreign_relation}, 'child', 'm2m far rel'; ok($m2m = (try { $class19->_m2m_metadata->{parents} }), 'many_to_many created'); - is $m2m->{relation}, 'loader_test20s', 'm2m near rel'; + is $m2m->{relation}, 'loader_test20', 'm2m near might_have rel'; is $m2m->{foreign_relation}, 'parent', 'm2m far rel'; # test double multi-col fk 26 -> 25 @@ -1723,7 +1723,7 @@ sub create { qq{ CREATE TABLE loader_test20 ( parent INTEGER NOT NULL, - child INTEGER NOT NULL, + child INTEGER NOT NULL UNIQUE, PRIMARY KEY (parent, child), FOREIGN KEY (parent) REFERENCES loader_test18 (id), FOREIGN KEY (child) REFERENCES loader_test19 (id)