X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FRelBuilder%2FCompat%2Fv0_040.pm;h=3f6daa5ac69a7c1751a4034bccc758880977af53;hb=5afd3e723f5c9644e67f9b623b069f870e94fdc9;hp=cc33c9067275be2b585950b20da797f04a37aef6;hpb=a8d229ff7be314991d1aa88122073f7102641ee9;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm index cc33c90..3f6daa5 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm @@ -3,34 +3,56 @@ package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040; use strict; use warnings; use Class::C3; - use base 'DBIx::Class::Schema::Loader::RelBuilder'; +use Carp::Clan qw/^DBIx::Class/; +use Lingua::EN::Inflect::Number (); + +our $VERSION = '0.06001'; + +sub _default_relationship_attrs { +{} } -sub _uniq_fk_rel { - my ($self, $local_moniker, $local_relname, $local_cols, $uniqs) = @_; +sub _to_PL { + my ($self, $name) = @_; - return ('has_many', $local_relname); + return Lingua::EN::Inflect::Number::to_PL($name); } -sub _remote_attrs { } +sub _to_S { + my ($self, $name) = @_; -sub _remote_relname { - my ($self, $remote_table, $cond) = @_; + return Lingua::EN::Inflect::Number::to_S($name); +} - 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) { - $remote_relname = $self->_inflect_singular(values %{$cond}); - } - else { - $remote_relname = $self->_inflect_singular(lc $remote_table); +sub _relnames_and_method { + my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_; + + my $remote_moniker = $rel->{remote_source}; + my $remote_table = $self->{schema}->source( $remote_moniker )->from; + + my $local_table = $self->{schema}->source($local_moniker)->from; + my $local_cols = $rel->{local_columns}; + + # for single-column case, set the remote relname to just the column name + my $remote_relname = + scalar keys %{$cond} == 1 + ? $self->_inflect_singular( values %$cond ) + : $self->_inflect_singular( lc $remote_table ); + + # If more than one rel between this pair of tables, use the local + # col names to distinguish + my $local_relname; + if ($counters->{$remote_moniker} > 1) { + my $colnames = '_' . join( '_', @$local_cols ); + $remote_relname .= $colnames if keys %$cond > 1; + $local_relname = $self->_inflect_plural( lc($local_table) . $colnames ); + } else { + $local_relname = $self->_inflect_plural(lc $local_table); } - return $remote_relname; + return ( $local_relname, $remote_relname, 'has_many' ); } -1; +sub _remote_attrs { } =head1 NAME @@ -39,6 +61,18 @@ compatibility with DBIx::Class::Schema::Loader version 0.04006 =head1 DESCRIPTION -See L. +See L and +L. + +=head1 AUTHOR + +See L and L. + +=head1 LICENSE + +This library is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. =cut + +1;