From: Brandon Black Date: Mon, 21 May 2007 18:41:04 +0000 (+0000) Subject: Merge 'trunk' into 'current' X-Git-Tag: 0.03999_02~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=54700b7184bbe8cc03aca5af92fedc25fffd12e5;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Merge 'trunk' into 'current' r31109@brandon-blacks-computer (orig r3316): blblack | 2007-05-15 08:53:49 -0500 Fix from Marc Espie for CREATE TABLE 'foo' for SQLite r31932@brandon-blacks-computer (orig r3342): ilmari | 2007-05-21 13:33:33 -0500 fix multiple multi-column relations to the same table implementation by Brandon L Black, tests by me r31933@brandon-blacks-computer (orig r3343): blblack | 2007-05-21 13:37:38 -0500 update Changes --- 54700b7184bbe8cc03aca5af92fedc25fffd12e5 diff --cc Changes index f3ff24a,12df3d1..d6db3e6 --- a/Changes +++ b/Changes @@@ -1,23 -1,10 +1,26 @@@ Revision history for Perl extension DBIx::Class::Schema::Loader + - Relationship names for multiple multi-col rels between + the same table fixed by ilmari + - Fix from Marc Espie for CREATE TABLE 'foo' for SQLite - skip ^sqlite_ tables in SQLite (thanks chromatic) +0.03999_01 Sat Apr 14 19:57:40 GMT 2007 + - Added *experimental* Oracle support from work done + by Tsunoda Kazuya some months ago. Not well tested. + - Added "rescan" schema (and loader) method, which picks + up newly created tables at runtime + - Made dump_to_dir / dump_overwrite much more intelligent + (they now preserve customizations by default) + - Added support for DBI's new standard "statistics_info" + method to gather unique key info (only supported by + DBD::Pg trunk afaik) + - columns_info_for imported from DBIx::Class + - relationships are now on by default, use skip_relationships + to disable them + - Removed previously deprecated methods/options + - Added $VERSION to all packages in this dist + 0.03011 Sat Apr 14 19:03:07 UTC 2007 - fix case-sensitivity in UNIQUE parsing for SQLite diff --cc lib/DBIx/Class/Schema/Loader/RelBuilder.pm index 35a50a8,5d22601..2b87753 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@@ -126,82 -130,87 +126,84 @@@ sub generate_code my $all_code = {}; - foreach my $local_moniker (keys %{$self->{fk_info}}) { - my $local_table = $self->{schema}->source($local_moniker)->from; - my $local_class = $self->{schema}->class($local_moniker); - my $rels = $self->{fk_info}->{$local_moniker}; + my $local_table = $self->{schema}->source($local_moniker)->from; + my $local_class = $self->{schema}->class($local_moniker); - my %counters; - foreach my $rel (@$rels) { - next if !$rel->{remote_source}; - $counters{$rel->{remote_source}}++; + my %counters; + foreach my $rel (@$rels) { + next if !$rel->{remote_source}; + $counters{$rel->{remote_source}}++; + } + + foreach my $rel (@$rels) { + next if !$rel->{remote_source}; + my $local_cols = $rel->{local_columns}; + my $remote_cols = $rel->{remote_columns}; + my $remote_moniker = $rel->{remote_source}; + my $remote_obj = $self->{schema}->source($remote_moniker); + my $remote_class = $self->{schema}->class($remote_moniker); + my $remote_table = $remote_obj->from; + $remote_cols ||= [ $remote_obj->primary_columns ]; + + if($#$local_cols != $#$remote_cols) { + croak "Column count mismatch: $local_moniker (@$local_cols) " + . "$remote_moniker (@$remote_cols)"; } - foreach my $rel (@$rels) { - next if !$rel->{remote_source}; - my $local_cols = $rel->{local_columns}; - my $remote_cols = $rel->{remote_columns}; - my $remote_moniker = $rel->{remote_source}; - my $remote_obj = $self->{schema}->source($remote_moniker); - my $remote_class = $self->{schema}->class($remote_moniker); - my $remote_table = $remote_obj->from; - $remote_cols ||= [ $remote_obj->primary_columns ]; - - if($#$local_cols != $#$remote_cols) { - croak "Column count mismatch: $local_moniker (@$local_cols) " - . "$remote_moniker (@$remote_cols)"; - } + my %cond; + foreach my $i (0 .. $#$local_cols) { + $cond{$remote_cols->[$i]} = $local_cols->[$i]; + } - # If more than one rel between this pair of tables, use the - # local col name(s) as the relname in the foreign source, instead - # of the local table name. - my %cond; - foreach my $i (0 .. $#$local_cols) { - $cond{$remote_cols->[$i]} = $local_cols->[$i]; - } + my $local_relname; - if($counters{$remote_moniker} > 1) { - $local_relname = $self->_inflect_plural( - lc($local_table) . q{_} . join(q{_}, @$local_cols) - ); - } else { - $local_relname = $self->_inflect_plural(lc $local_table); - } - - # for single-column case, set the relname to the column name, - # to make filter accessors work + my $remote_relname; + - my $local_relname; - my $remote_relname; ++ # for single-column case, set the remote relname to the column ++ # name, to make filter accessors work + if(scalar keys %cond == 1) { + my ($col) = keys %cond; + $remote_relname = $self->_inflect_singular($cond{$col}); + } + else { + $remote_relname = $self->_inflect_singular(lc $remote_table); + } - # for single-column case, set the remote relname to the column - # name, to make filter accessors work - if(scalar keys %cond == 1) { - my ($col) = keys %cond; - $remote_relname = $self->_inflect_singular($cond{$col}); - } - else { - $remote_relname = $self->_inflect_singular(lc $remote_table); - } ++ # If more than one rel between this pair of tables, use the local ++ # col names to distinguish ++ if($counters{$remote_moniker} > 1) { ++ my $colnames = q{_} . join(q{_}, @$local_cols); ++ $local_relname = $self->_inflect_plural( ++ lc($local_table) . $colnames ++ ); ++ $remote_relname .= $colnames if keys %cond > 1; ++ } else { ++ $local_relname = $self->_inflect_plural(lc $local_table); ++ } + - # If more than one rel between this pair of tables, use the local - # col names to distinguish - if($counters{$remote_moniker} > 1) { - my $colnames = q{_} . join(q{_}, @$local_cols); - $local_relname = $self->_inflect_plural( - lc($local_table) . $colnames - ); - $remote_relname .= $colnames if keys %cond > 1; - } else { - $local_relname = $self->_inflect_plural(lc $local_table); - } + my %rev_cond = reverse %cond; - my %rev_cond = reverse %cond; + for (keys %rev_cond) { + $rev_cond{"foreign.$_"} = "self.".$rev_cond{$_}; + delete $rev_cond{$_}; + } - for (keys %rev_cond) { - $rev_cond{"foreign.$_"} = "self.".$rev_cond{$_}; - delete $rev_cond{$_}; + push(@{$all_code->{$local_class}}, + { method => 'belongs_to', + args => [ $remote_relname, + $remote_class, + \%cond, + ], } - - push(@{$all_code->{$local_class}}, - { method => 'belongs_to', - args => [ $remote_relname, - $remote_class, - \%cond, - ], - } - ); - - push(@{$all_code->{$remote_class}}, - { method => 'has_many', - args => [ $local_relname, - $local_class, - \%rev_cond, - ], - } - ); - } + ); + + push(@{$all_code->{$remote_class}}, + { method => 'has_many', + args => [ $local_relname, + $local_class, + \%rev_cond, + ], + } + ); } return $all_code; diff --cc t/lib/dbixcsl_common_tests.pm index 2bad164,f15e6f3..aa8ee67 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@@ -43,7 -43,7 +43,7 @@@ sub _monikerize sub run_tests { my $self = shift; - plan tests => 80; - plan tests => 84; ++ plan tests => 88; $self->create();