use Carp::Clan qw/^DBIx::Class/;
use Lingua::EN::Inflect::Number ();
-our $VERSION = '0.05002';
+our $VERSION = '0.05003';
=head1 NAME
sub _inflect_plural {
my ($self, $relname) = @_;
+ return '' if !defined $relname || $relname eq '';
+
if( ref $self->{inflect_plural} eq 'HASH' ) {
return $self->{inflect_plural}->{$relname}
if exists $self->{inflect_plural}->{$relname};
sub _inflect_singular {
my ($self, $relname) = @_;
+ return '' if !defined $relname || $relname eq '';
+
if( ref $self->{inflect_singular} eq 'HASH' ) {
return $self->{inflect_singular}->{$relname}
if exists $self->{inflect_singular}->{$relname};
# name, to make filter accessors work, but strip trailing _id
if(scalar keys %{$cond} == 1) {
my ($col) = values %{$cond};
+ $col = lc $col;
$col =~ s/_id$//;
$remote_relname = $self->_inflect_singular($col);
}
}
my ( $local_relname, $remote_relname, $remote_method ) =
- $self->_relnames_and_methods( $local_moniker, $rel, \%cond, $uniqs, \%counters );
+ $self->_relnames_and_method( $local_moniker, $rel, \%cond, $uniqs, \%counters );
push(@{$all_code->{$local_class}},
{ method => 'belongs_to',
return $all_code;
}
-sub _relnames_and_methods {
+sub _relnames_and_method {
my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_;
my $remote_moniker = $rel->{remote_source};
my $remote_obj = $self->{schema}->source( $remote_moniker );
my $remote_class = $self->{schema}->class( $remote_moniker );
- my $remote_relname = $self->_remote_relname( $remote_obj->from, $cond);
+ my $remote_relname = lc $self->_remote_relname( $remote_obj->from, $cond);
my $local_cols = $rel->{local_columns};
my $local_table = $self->{schema}->source($local_moniker)->from;
# If more than one rel between this pair of tables, use the local
# col names to distinguish
my $local_relname;
+ my $old_multirel_name; #< TODO: remove me
if ( $counters->{$remote_moniker} > 1) {
- my $colnames = q{_} . join(q{_}, @$local_cols);
+ my $colnames = lc(q{_} . join(q{_}, @$local_cols));
$remote_relname .= $colnames if keys %$cond > 1;
- my $old_relname = #< TODO: remove me after 0.05003 release
$local_relname = lc($local_table) . $colnames;
- my $stripped_id = $local_relname =~ s/_id$//; #< strip off any trailing _id
+ $local_relname =~ s/_id$//
+ #< TODO: remove me
+ and $old_multirel_name = $self->_inflect_plural( lc($local_table) . $colnames );
$local_relname = $self->_inflect_plural( $local_relname );
- # TODO: remove me after 0.05003 release
- $old_relname = $self->_inflect_plural( $old_relname );
- warn __PACKAGE__." $VERSION: warning, stripping trailing _id from ${remote_class} relation '$old_relname', renaming to '$local_relname'. This behavior is new as of 0.05003.\n"
- if $stripped_id;
-
} else {
$local_relname = $self->_inflect_plural(lc $local_table);
}
grep { _array_eq($_->[1], $local_cols) } @$uniqs) {
$remote_method = 'might_have';
$local_relname = $self->_inflect_singular($local_relname);
+ #< TODO: remove me
+ $old_multirel_name = $self->_inflect_singular($old_multirel_name);
}
+ # TODO: remove me after 0.05003 release
+ $old_multirel_name
+ and warn __PACKAGE__." $VERSION: warning, stripping trailing _id from ${remote_class} relation '$old_multirel_name', renaming to '$local_relname'. This behavior is new as of 0.05003.\n";
+
return ( $local_relname, $remote_relname, $remote_method );
}