smarter inflect_plural in RelBuilder
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / RelBuilder / Compat / v0_040.pm
CommitLineData
7824616e 1package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040;
2
3use strict;
4use warnings;
5use Class::C3;
6
7use base 'DBIx::Class::Schema::Loader::RelBuilder';
8
c496748b 9sub _to_PL {
10 my ($self, $name) = @_;
11
12 return Lingua::EN::Inflect::Number::to_PL($name);
13}
14
39ef3bfe 15sub _relnames_and_method {
057fbb08 16 my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_;
17
18 my $remote_moniker = $rel->{remote_source};
19 my $remote_table = $self->{schema}->source( $remote_moniker )->from;
20
21 my $local_table = $self->{schema}->source($local_moniker)->from;
22 my $local_cols = $rel->{local_columns};
23
24 # for single-column case, set the remote relname to just the column name
25 my $remote_relname =
26 scalar keys %{$cond} == 1
27 ? $self->_inflect_singular( values %$cond )
28 : $self->_inflect_singular( lc $remote_table );
29
30 # If more than one rel between this pair of tables, use the local
31 # col names to distinguish
32 my $local_relname;
33 if ($counters->{$remote_moniker} > 1) {
34 my $colnames = '_' . join( '_', @$local_cols );
35 $remote_relname .= $colnames if keys %$cond > 1;
36 $local_relname = $self->_inflect_plural( lc($local_table) . $colnames );
37 } else {
38 $local_relname = $self->_inflect_plural(lc $local_table);
7824616e 39 }
40
057fbb08 41 return ( $local_relname, $remote_relname, 'has_many' );
7824616e 42}
43
057fbb08 44sub _remote_attrs { }
fa6f8d4e 45
7824616e 461;
818c6a0c 47
48=head1 NAME
49
50DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040 - RelBuilder for
51compatibility with DBIx::Class::Schema::Loader version 0.04006
52
53=head1 DESCRIPTION
54
a8d229ff 55See L<DBIx::Class::Schema::Loader::Base/naming>.
818c6a0c 56
57=cut