From: Dagfinn Ilmari Mannsåker Date: Sun, 11 Aug 2013 11:00:51 +0000 (+0100) Subject: Allow specifying custom attributes for many_to_many bridges X-Git-Tag: 0.07036_01~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ce62007019b630d74636a684bbcfb0d07c81e289;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Allow specifying custom attributes for many_to_many bridges --- diff --git a/Changes b/Changes index 741efb3..36c80b1 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,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 + - Allow specifying custom attributes for many_to_many bridges 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 710ea54..49df4b0 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -605,6 +605,16 @@ sub _generate_m2ms { $class1_to_class2_relname, $class1_to_link_table_rel_name, $class1_link_rel, + $self->_relationship_attrs('many_to_many', {}, { + rel_type => 'many_to_many', + rel_name => $class1_to_class2_relname, + local_source => $self->schema->source($class1_local_moniker), + remote_source => $self->schema->source($class1_remote_moniker), + local_table => $self->loader->class_to_table->{$class1}, + local_cols => \@class1_from_cols, + remote_table => $self->loader->class_to_table->{$class2}, + remote_cols => \@class2_from_cols, + }) || (), ], extra => { local_class => $class1, @@ -620,6 +630,16 @@ sub _generate_m2ms { $class2_to_class1_relname, $class2_to_link_table_rel_name, $class2_link_rel, + $self->_relationship_attrs('many_to_many', {}, { + rel_type => 'many_to_many', + rel_name => $class2_to_class1_relname, + local_source => $self->schema->source($class2_local_moniker), + remote_source => $self->schema->source($class2_remote_moniker), + local_table => $self->loader->class_to_table->{$class2}, + local_cols => \@class2_from_cols, + remote_table => $self->loader->class_to_table->{$class1}, + remote_cols => \@class1_from_cols, + }) || (), ], extra => { local_class => $class2, diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 92dda03..1425e2f 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -119,7 +119,7 @@ sub run_tests { $num_rescans++ if $self->{vendor} eq 'Firebird'; plan tests => @connect_info * - (221 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0)); + (223 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0)); foreach my $info_idx (0..$#connect_info) { my $info = $connect_info[$info_idx]; @@ -254,6 +254,7 @@ sub setup_schema { ) : (), col_collision_map => { '^(can)\z' => 'caught_collision_%s' }, rel_collision_map => { '^(set_primary_key)\z' => 'caught_rel_collision_%s' }, + relationship_attrs => { many_to_many => { order_by => 'me.id' } }, col_accessor_map => \&test_col_accessor_map, result_components_map => { LoaderTest2X => 'TestComponentForMap', LoaderTest1 => '+TestComponentForMapFQN' }, uniq_to_primary => 1, @@ -929,11 +930,13 @@ qr/\n__PACKAGE__->(?:belongs_to|has_many|might_have|has_one|many_to_many)\( is $m2m->{relation}, 'loader_test20s', 'm2m near has_many rel'; is $m2m->{foreign_relation}, 'child', 'm2m far rel'; + is $m2m->{attrs}->{order_by}, 'me.id', 'm2m bridge attrs'; ok($m2m = (try { $class19->_m2m_metadata->{parents} }), 'many_to_many created'); is $m2m->{relation}, 'loader_test20', 'm2m near might_have rel'; is $m2m->{foreign_relation}, 'parent', 'm2m far rel'; + is $m2m->{attrs}->{order_by}, 'me.id', 'm2m bridge attrs'; # test double multi-col fk 26 -> 25 my $obj26 = try { $rsobj26->find(33) } || $rsobj26->search({ id => 33 })->single;