revert 45a380dc2d68e828de4011b99f0c3739db5b0707
[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;
ecf930e6 6use base 'DBIx::Class::Schema::Loader::RelBuilder';
7use Carp::Clan qw/^DBIx::Class/;
39b22ca9 8use Lingua::EN::Inflect::Number ();
7824616e 9
9990e58f 10our $VERSION = '0.07000';
7824616e 11
53ef681d 12sub _default_relationship_attrs { +{} }
13
c496748b 14sub _to_PL {
15 my ($self, $name) = @_;
16
17 return Lingua::EN::Inflect::Number::to_PL($name);
18}
19
39b22ca9 20sub _to_S {
21 my ($self, $name) = @_;
22
23 return Lingua::EN::Inflect::Number::to_S($name);
24}
25
39ef3bfe 26sub _relnames_and_method {
057fbb08 27 my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_;
28
29 my $remote_moniker = $rel->{remote_source};
30 my $remote_table = $self->{schema}->source( $remote_moniker )->from;
31
32 my $local_table = $self->{schema}->source($local_moniker)->from;
33 my $local_cols = $rel->{local_columns};
34
35 # for single-column case, set the remote relname to just the column name
36 my $remote_relname =
37 scalar keys %{$cond} == 1
38 ? $self->_inflect_singular( values %$cond )
39 : $self->_inflect_singular( lc $remote_table );
40
41 # If more than one rel between this pair of tables, use the local
42 # col names to distinguish
43 my $local_relname;
44 if ($counters->{$remote_moniker} > 1) {
45 my $colnames = '_' . join( '_', @$local_cols );
46 $remote_relname .= $colnames if keys %$cond > 1;
47 $local_relname = $self->_inflect_plural( lc($local_table) . $colnames );
48 } else {
49 $local_relname = $self->_inflect_plural(lc $local_table);
7824616e 50 }
51
057fbb08 52 return ( $local_relname, $remote_relname, 'has_many' );
7824616e 53}
54
057fbb08 55sub _remote_attrs { }
fa6f8d4e 56
818c6a0c 57=head1 NAME
58
59DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040 - RelBuilder for
60compatibility with DBIx::Class::Schema::Loader version 0.04006
61
62=head1 DESCRIPTION
63
ecf930e6 64See L<DBIx::Class::Schema::Loader::Base/naming> and
65L<DBIx::Class::Schema::Loader::RelBuilder>.
66
67=head1 AUTHOR
68
69See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
70
71=head1 LICENSE
72
73This library is free software; you can redistribute it and/or modify it under
74the same terms as Perl itself.
818c6a0c 75
76=cut
ecf930e6 77
781;