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