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