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