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