Commit | Line | Data |
7824616e |
1 | package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use Class::C3; |
ecf930e6 |
6 | use base 'DBIx::Class::Schema::Loader::RelBuilder'; |
7 | use Carp::Clan qw/^DBIx::Class/; |
39b22ca9 |
8 | use Lingua::EN::Inflect::Number (); |
7824616e |
9 | |
9990e58f |
10 | our $VERSION = '0.07000'; |
7824616e |
11 | |
53ef681d |
12 | sub _default_relationship_attrs { +{} } |
13 | |
c496748b |
14 | sub _to_PL { |
15 | my ($self, $name) = @_; |
16 | |
17 | return Lingua::EN::Inflect::Number::to_PL($name); |
18 | } |
19 | |
39b22ca9 |
20 | sub _to_S { |
21 | my ($self, $name) = @_; |
22 | |
23 | return Lingua::EN::Inflect::Number::to_S($name); |
24 | } |
25 | |
39ef3bfe |
26 | sub _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 |
55 | sub _remote_attrs { } |
fa6f8d4e |
56 | |
818c6a0c |
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 | |
ecf930e6 |
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. |
818c6a0c |
75 | |
76 | =cut |
ecf930e6 |
77 | |
78 | 1; |