Commit | Line | Data |
ecf930e6 |
1 | package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_05; |
2 | |
3 | use strict; |
4 | use warnings; |
19b7d71c |
5 | use base 'DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_06'; |
c4a69b87 |
6 | use mro 'c3'; |
ecf930e6 |
7 | use Lingua::EN::Inflect::Number (); |
8 | |
4295c4b4 |
9 | our $VERSION = '0.07010'; |
ecf930e6 |
10 | |
11 | sub _to_PL { |
12 | my ($self, $name) = @_; |
13 | |
14 | return Lingua::EN::Inflect::Number::to_PL($name); |
15 | } |
16 | |
17 | sub _to_S { |
18 | my ($self, $name) = @_; |
19 | |
20 | return Lingua::EN::Inflect::Number::to_S($name); |
21 | } |
22 | |
23 | sub _default_relationship_attrs { +{} } |
24 | |
25 | sub _relnames_and_method { |
26 | my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_; |
27 | |
28 | my $remote_moniker = $rel->{remote_source}; |
29 | my $remote_obj = $self->{schema}->source( $remote_moniker ); |
30 | my $remote_class = $self->{schema}->class( $remote_moniker ); |
c4a69b87 |
31 | my $remote_relname = $self->_remote_relname( $rel->{remote_table}, $cond); |
ecf930e6 |
32 | |
33 | my $local_cols = $rel->{local_columns}; |
c4a69b87 |
34 | my $local_table = $rel->{local_table}; |
ecf930e6 |
35 | |
36 | # If more than one rel between this pair of tables, use the local |
37 | # col names to distinguish |
38 | my ($local_relname, $local_relname_uninflected); |
39 | if ( $counters->{$remote_moniker} > 1) { |
40 | my $colnames = lc(q{_} . join(q{_}, map lc($_), @$local_cols)); |
41 | $remote_relname .= $colnames if keys %$cond > 1; |
42 | |
43 | $local_relname = lc($local_table) . $colnames; |
44 | |
45 | $local_relname_uninflected = $local_relname; |
404aefa4 |
46 | ($local_relname) = $self->_inflect_plural( $local_relname ); |
ecf930e6 |
47 | } else { |
48 | $local_relname_uninflected = lc $local_table; |
404aefa4 |
49 | ($local_relname) = $self->_inflect_plural(lc $local_table); |
ecf930e6 |
50 | } |
51 | |
52 | my $remote_method = 'has_many'; |
53 | |
54 | # If the local columns have a UNIQUE constraint, this is a one-to-one rel |
55 | my $local_source = $self->{schema}->source($local_moniker); |
56 | if ($self->_array_eq([ $local_source->primary_columns ], $local_cols) || |
57 | grep { $self->_array_eq($_->[1], $local_cols) } @$uniqs) { |
58 | $remote_method = 'might_have'; |
404aefa4 |
59 | ($local_relname) = $self->_inflect_singular($local_relname_uninflected); |
ecf930e6 |
60 | } |
61 | |
62 | return ( $local_relname, $remote_relname, $remote_method ); |
63 | } |
64 | |
65 | =head1 NAME |
66 | |
67 | DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_05 - RelBuilder for |
19b7d71c |
68 | compatibility with DBIx::Class::Schema::Loader version 0.05003 |
ecf930e6 |
69 | |
70 | =head1 DESCRIPTION |
71 | |
72 | See L<DBIx::Class::Schema::Loader::Base/naming> and |
73 | L<DBIx::Class::Schema::Loader::RelBuilder>. |
74 | |
75 | =head1 AUTHOR |
76 | |
77 | See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>. |
78 | |
79 | =head1 LICENSE |
80 | |
81 | This library is free software; you can redistribute it and/or modify it under |
82 | the same terms as Perl itself. |
83 | |
84 | =cut |
85 | |
86 | 1; |