turn off cascade_delete/copy, set on_delete/update
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / RelBuilder / Compat / v0_040.pm
CommitLineData
7824616e 1package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040;
2
3use strict;
4use warnings;
5use Class::C3;
6
7use base 'DBIx::Class::Schema::Loader::RelBuilder';
8
53ef681d 9sub _default_relationship_attrs { +{} }
10
c496748b 11sub _to_PL {
12 my ($self, $name) = @_;
13
14 return Lingua::EN::Inflect::Number::to_PL($name);
15}
16
39ef3bfe 17sub _relnames_and_method {
057fbb08 18 my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_;
19
20 my $remote_moniker = $rel->{remote_source};
21 my $remote_table = $self->{schema}->source( $remote_moniker )->from;
22
23 my $local_table = $self->{schema}->source($local_moniker)->from;
24 my $local_cols = $rel->{local_columns};
25
26 # for single-column case, set the remote relname to just the column name
27 my $remote_relname =
28 scalar keys %{$cond} == 1
29 ? $self->_inflect_singular( values %$cond )
30 : $self->_inflect_singular( lc $remote_table );
31
32 # If more than one rel between this pair of tables, use the local
33 # col names to distinguish
34 my $local_relname;
35 if ($counters->{$remote_moniker} > 1) {
36 my $colnames = '_' . join( '_', @$local_cols );
37 $remote_relname .= $colnames if keys %$cond > 1;
38 $local_relname = $self->_inflect_plural( lc($local_table) . $colnames );
39 } else {
40 $local_relname = $self->_inflect_plural(lc $local_table);
7824616e 41 }
42
057fbb08 43 return ( $local_relname, $remote_relname, 'has_many' );
7824616e 44}
45
057fbb08 46sub _remote_attrs { }
fa6f8d4e 47
7824616e 481;
818c6a0c 49
50=head1 NAME
51
52DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040 - RelBuilder for
53compatibility with DBIx::Class::Schema::Loader version 0.04006
54
55=head1 DESCRIPTION
56
a8d229ff 57See L<DBIx::Class::Schema::Loader::Base/naming>.
818c6a0c 58
59=cut