1d40f4c54597dc18699dc70aef695fa78cee651a
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / RelBuilder / Compat / v0_040.pm
1 package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040;
2
3 use strict;
4 use warnings;
5 use Class::C3;
6 use base 'DBIx::Class::Schema::Loader::RelBuilder';
7 use Carp::Clan qw/^DBIx::Class/;
8 use Lingua::EN::Inflect::Number ();
9
10 our $VERSION = '0.07000';
11
12 sub _default_relationship_attrs { +{} }
13
14 sub _to_PL {
15     my ($self, $name) = @_;
16
17     return Lingua::EN::Inflect::Number::to_PL($name);
18 }
19
20 sub _to_S {
21     my ($self, $name) = @_;
22
23     return Lingua::EN::Inflect::Number::to_S($name);
24 }
25
26 sub _relnames_and_method {
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);
50     }
51
52     return ( $local_relname, $remote_relname, 'has_many' );
53 }
54
55 sub _remote_attrs { }
56
57 =head1 NAME
58
59 DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040 - RelBuilder for
60 compatibility with DBIx::Class::Schema::Loader version 0.04006
61
62 =head1 DESCRIPTION
63
64 See L<DBIx::Class::Schema::Loader::Base/naming> and
65 L<DBIx::Class::Schema::Loader::RelBuilder>.
66
67 =head1 AUTHOR
68
69 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
70
71 =head1 LICENSE
72
73 This library is free software; you can redistribute it and/or modify it under
74 the same terms as Perl itself.
75
76 =cut
77
78 1;