1 package DBIx::Class::Schema::Loader::RelBuilder;
5 use base 'Class::Accessor::Grouped';
7 use Carp::Clan qw/^DBIx::Class/;
8 use Scalar::Util 'weaken';
9 use DBIx::Class::Schema::Loader::Utils qw/split_name slurp_file array_eq/;
11 use List::Util 'first';
12 use List::MoreUtils qw/apply uniq any all/;
14 use Lingua::EN::Inflect::Phrase ();
15 use Lingua::EN::Tagger ();
16 use String::ToIdentifier::EN ();
17 use String::ToIdentifier::EN::Unicode ();
19 use Class::Inspector ();
21 our $VERSION = '0.07042';
25 # local_relname -- name of relationship from the local table referring to the remote table
26 # remote_relname -- name of relationship from the remote table referring to the local table
27 # remote_method -- relationship type from remote table to local table, usually has_many
31 DBIx::Class::Schema::Loader::RelBuilder - Builds relationships for DBIx::Class::Schema::Loader
35 See L<DBIx::Class::Schema::Loader> and L<DBIx::Class::Schema::Loader::Base>.
39 This class builds relationships for L<DBIx::Class::Schema::Loader>. This
40 is module is not (yet) for external use.
46 Arguments: $loader object
53 [ local_moniker1 (scalar), fk_info1 (arrayref), uniq_info1 (arrayref) ]
54 [ local_moniker2 (scalar), fk_info2 (arrayref), uniq_info2 (arrayref) ]
58 This generates the code for the relationships of each table.
60 C<local_moniker> is the moniker name of the table which had the REFERENCES
61 statements. The fk_info arrayref's contents should take the form:
65 local_table => 'some_table',
66 local_moniker => 'SomeTable',
67 local_columns => [ 'col2', 'col3' ],
68 remote_table => 'another_table_moniker',
69 remote_moniker => 'AnotherTableMoniker',
70 remote_columns => [ 'col5', 'col7' ],
73 local_table => 'some_other_table',
74 local_moniker => 'SomeOtherTable',
75 local_columns => [ 'col1', 'col4' ],
76 remote_table => 'yet_another_table_moniker',
77 remote_moniker => 'YetAnotherTableMoniker',
78 remote_columns => [ 'col1', 'col2' ],
83 The uniq_info arrayref's contents should take the form:
87 uniq_constraint_name => [ 'col1', 'col2' ],
90 another_uniq_constraint_name => [ 'col1', 'col2' ],
94 This method will return the generated relationships as a hashref keyed on the
95 class names. The values are arrayrefs of hashes containing method name and
99 'Some::Source::Class' => [
100 { method => 'belongs_to', arguments => [ 'col1', 'Another::Source::Class' ],
101 { method => 'has_many', arguments => [ 'anothers', 'Yet::Another::Source::Class', 'col15' ],
103 'Another::Source::Class' => [
111 __PACKAGE__->mk_group_accessors('simple', qw/
124 my ($class, $loader) = @_;
126 # from old POD about this constructor:
127 # C<$schema_class> should be a schema class name, where the source
128 # classes have already been set up and registered. Column info,
129 # primary key, and unique constraints will be drawn from this
130 # schema for all of the existing source monikers.
132 # Options inflect_plural and inflect_singular are optional, and
133 # are better documented in L<DBIx::Class::Schema::Loader::Base>.
137 schema => $loader->schema,
138 inflect_plural => $loader->inflect_plural,
139 inflect_singular => $loader->inflect_singular,
140 relationship_attrs => $loader->relationship_attrs,
141 rel_collision_map => $loader->rel_collision_map,
142 rel_name_map => $loader->rel_name_map,
146 weaken $self->{loader}; #< don't leak
148 bless $self => $class;
150 # validate the relationship_attrs arg
151 if( defined $self->relationship_attrs ) {
152 (ref $self->relationship_attrs eq 'HASH' || ref $self->relationship_attrs eq 'CODE')
153 or croak "relationship_attrs must be a hashref or coderef";
160 # pluralize a relationship name
161 sub _inflect_plural {
162 my ($self, $relname) = @_;
164 return '' if !defined $relname || $relname eq '';
169 if( ref $self->inflect_plural eq 'HASH' ) {
170 if (exists $self->inflect_plural->{$relname}) {
171 $result = $self->inflect_plural->{$relname};
175 elsif( ref $self->inflect_plural eq 'CODE' ) {
176 my $inflected = $self->inflect_plural->($relname);
178 $result = $inflected;
183 return ($result, $mapped) if $mapped;
185 return ($self->_to_PL($relname), 0);
188 # Singularize a relationship name
189 sub _inflect_singular {
190 my ($self, $relname) = @_;
192 return '' if !defined $relname || $relname eq '';
197 if( ref $self->inflect_singular eq 'HASH' ) {
198 if (exists $self->inflect_singular->{$relname}) {
199 $result = $self->inflect_singular->{$relname};
203 elsif( ref $self->inflect_singular eq 'CODE' ) {
204 my $inflected = $self->inflect_singular->($relname);
206 $result = $inflected;
211 return ($result, $mapped) if $mapped;
213 return ($self->_to_S($relname), 0);
217 my ($self, $name) = @_;
220 my $plural = Lingua::EN::Inflect::Phrase::to_PL($name);
227 my ($self, $name) = @_;
230 my $singular = Lingua::EN::Inflect::Phrase::to_S($name);
231 $singular =~ s/ /_/g;
236 sub _default_relationship_attrs { +{
246 on_delete => 'CASCADE',
247 on_update => 'CASCADE',
252 # Accessor for options to be passed to each generated relationship type. takes
253 # the relationship type name and optionally any attributes from the database
254 # (such as FK ON DELETE/UPDATE and DEFERRABLE clauses), and returns a
255 # hashref or undef if nothing is set.
257 # The attributes from the database override the default attributes, which in
258 # turn are overridden by user supplied attributes.
259 sub _relationship_attrs {
260 my ( $self, $reltype, $db_attrs, $params ) = @_;
261 my $r = $self->relationship_attrs;
264 %{ $self->_default_relationship_attrs->{$reltype} || {} },
265 %{ $db_attrs || {} },
268 %{ $r->{all} || {} },
269 %{ $r->{$reltype} || {} },
276 if (ref $r eq 'CODE') {
277 $params->{attrs} = \%composite;
279 my %ret = %{ $r->(%$params) || {} };
281 %composite = %ret if %ret;
284 return %composite ? \%composite : undef;
287 sub _strip_id_postfix {
288 my ($self, $name) = @_;
290 $name =~ s/_?(?:id|ref|cd|code|num)\z//i;
296 my ($self, $local_moniker, $local_cols, $fk_attrs, $params) = @_;
298 # get our set of attrs from _relationship_attrs, which uses the FK attrs if available
299 my $attrs = $self->_relationship_attrs('belongs_to', $fk_attrs, $params) || {};
301 # If any referring column is nullable, make 'belongs_to' an
302 # outer join, unless explicitly set by relationship_attrs
303 my $nullable = first { $self->schema->source($local_moniker)->column_info($_)->{is_nullable} } @$local_cols;
304 $attrs->{join_type} = 'LEFT' if $nullable && !defined $attrs->{join_type};
310 my ($self, $name) = @_;
312 $name = $self->loader->_to_identifier('relationships', $name, '_');
314 $name =~ s/\W+/_/g; # if naming >= 8 to_identifier takes care of it
319 sub _normalize_name {
320 my ($self, $name) = @_;
322 $name = $self->_sanitize_name($name);
324 my @words = split_name $name, $self->loader->_get_naming_v('relationships');
326 return join '_', map lc, @words;
330 my ($self, $remote_table, $cond) = @_;
333 # for single-column case, set the remote relname to the column
334 # name, to make filter accessors work, but strip trailing _id
335 if(scalar keys %{$cond} == 1) {
336 my ($col) = values %{$cond};
337 $col = $self->_strip_id_postfix($self->_normalize_name($col));
338 ($local_relname) = $self->_inflect_singular($col);
341 ($local_relname) = $self->_inflect_singular($self->_normalize_name($remote_table));
344 return $local_relname;
347 sub _resolve_relname_collision {
348 my ($self, $moniker, $cols, $relname) = @_;
350 return $relname if $relname eq 'id'; # this shouldn't happen, but just in case
352 my $table = $self->loader->moniker_to_table->{$moniker};
354 if ($self->loader->_is_result_class_method($relname, $table)) {
355 if (my $map = $self->rel_collision_map) {
356 for my $re (keys %$map) {
357 if (my @matches = $relname =~ /$re/) {
358 return sprintf $map->{$re}, @matches;
363 my $new_relname = $relname;
364 while ($self->loader->_is_result_class_method($new_relname, $table)) {
365 $new_relname .= '_rel'
369 Relationship '$relname' in source '$moniker' for columns '@{[ join ',', @$cols ]}' collides with an inherited method. Renaming to '$new_relname'.
370 See "RELATIONSHIP NAME COLLISIONS" in perldoc DBIx::Class::Schema::Loader::Base .
380 my ($self, $tables) = @_;
382 # make a copy to destroy
383 my @tables = @$tables;
387 while (my ($local_moniker, $rels, $uniqs) = @{ shift @tables || [] }) {
388 my $local_class = $self->schema->class($local_moniker);
391 foreach my $rel (@$rels) {
392 next if !$rel->{remote_source};
393 $counters{$rel->{remote_source}}++;
396 foreach my $rel (@$rels) {
397 my $remote_moniker = $rel->{remote_source}
400 my $remote_class = $self->schema->class($remote_moniker);
401 my $remote_obj = $self->schema->source($remote_moniker);
402 my $remote_cols = $rel->{remote_columns} || [ $remote_obj->primary_columns ];
404 my $local_cols = $rel->{local_columns};
406 if($#$local_cols != $#$remote_cols) {
407 croak "Column count mismatch: $local_moniker (@$local_cols) "
408 . "$remote_moniker (@$remote_cols)";
412 @cond{@$remote_cols} = @$local_cols;
414 my ( $local_relname, $remote_relname, $remote_method ) =
415 $self->_relnames_and_method( $local_moniker, $rel, \%cond, $uniqs, \%counters );
416 my $local_method = 'belongs_to';
418 ($local_relname) = $self->_rel_name_map(
419 $local_relname, $local_method,
420 $local_class, $local_moniker, $local_cols,
421 $remote_class, $remote_moniker, $remote_cols,
423 ($remote_relname) = $self->_rel_name_map(
424 $remote_relname, $remote_method,
425 $remote_class, $remote_moniker, $remote_cols,
426 $local_class, $local_moniker, $local_cols,
429 $local_relname = $self->_resolve_relname_collision(
430 $local_moniker, $local_cols, $local_relname,
432 $remote_relname = $self->_resolve_relname_collision(
433 $remote_moniker, $remote_cols, $remote_relname,
436 my $rel_attrs_params = {
437 rel_name => $local_relname,
438 rel_type => $local_method,
439 local_source => $self->schema->source($local_moniker),
440 remote_source => $self->schema->source($remote_moniker),
441 local_table => $rel->{local_table},
442 local_cols => $local_cols,
443 remote_table => $rel->{remote_table},
444 remote_cols => $remote_cols,
447 push @{$all_code->{$local_class}}, {
448 method => $local_method,
453 $self->_remote_attrs($local_moniker, $local_cols, $rel->{attrs}, $rel_attrs_params),
456 local_class => $local_class,
457 local_moniker => $local_moniker,
458 remote_moniker => $remote_moniker,
462 my %rev_cond = reverse %cond;
463 for (keys %rev_cond) {
464 $rev_cond{"foreign.$_"} = "self.".$rev_cond{$_};
465 delete $rev_cond{$_};
468 $rel_attrs_params = {
469 rel_name => $remote_relname,
470 rel_type => $remote_method,
471 local_source => $self->schema->source($remote_moniker),
472 remote_source => $self->schema->source($local_moniker),
473 local_table => $rel->{remote_table},
474 local_cols => $remote_cols,
475 remote_table => $rel->{local_table},
476 remote_cols => $local_cols,
479 push @{$all_code->{$remote_class}}, {
480 method => $remote_method,
485 $self->_relationship_attrs($remote_method, {}, $rel_attrs_params),
488 local_class => $remote_class,
489 local_moniker => $remote_moniker,
490 remote_moniker => $local_moniker,
496 $self->_generate_m2ms($all_code);
498 # disambiguate rels with the same name
499 foreach my $class (keys %$all_code) {
500 my $dups = $self->_duplicates($all_code->{$class});
502 $self->_disambiguate($all_code, $class, $dups) if $dups;
510 # Find classes with only 2 FKs which are the PK and make many_to_many bridges for them.
512 my ($self, $all_code) = @_;
515 foreach my $link_class (sort keys %$all_code) {
516 my @rels = grep $_->{method} eq 'belongs_to', @{$all_code->{$link_class}};
517 next unless @rels == 2;
520 foreach my $this (0, 1) {
521 my $that = $this ? 0 : 1;
523 $class[$this] = \%class;
524 $class{local_moniker} = $rels[$this]{extra}{remote_moniker};
525 $class{remote_moniker} = $rels[$that]{extra}{remote_moniker};
527 $class{class} = $rels[$this]{args}[1];
529 my %link_cols = map { $_ => 1 } apply { s/^self\.//i } values %{ $rels[$this]{args}[2] };
531 $class{link_table_rel} = first {
532 $_->{method} eq 'has_many'
534 $_->{args}[1] eq $link_class
536 all { $link_cols{$_} } apply { s/^foreign\.//i } keys %{$_->{args}[2]}
537 } @{ $all_code->{$class{class}} };
539 next LINK_CLASS unless $class{link_table_rel};
541 $class{link_table_rel_name} = $class{link_table_rel}{args}[0];
543 $class{link_rel} = $rels[$that]{args}[0];
545 $class{from_cols} = [ apply { s/^self\.//i } values %{
546 $class{link_table_rel}->{args}[2]
549 $class{to_cols} = [ apply { s/^foreign\.//i } keys %{ $rels[$that]{args}[2] } ];
551 $class{from_link_cols} = [ apply { s/^self\.//i } values %{ $rels[$this]{args}[2] } ];
554 my $link_moniker = $rels[0]{extra}{local_moniker};
556 my @link_table_cols =
557 @{[ $self->schema->source($link_moniker)->columns ]};
559 my @link_table_primary_cols =
560 @{[ $self->schema->source($link_moniker)->primary_columns ]};
562 next unless uniq(@{$class[0]{from_link_cols}}, @{$class[1]{from_link_cols}}) == @link_table_cols
563 && @link_table_cols == @link_table_primary_cols;
565 foreach my $this (0, 1) {
566 my $that = $this ? 0 : 1;
567 ($class[$this]{m2m_relname}) = $self->_rel_name_map(
568 ($self->_inflect_plural($class[$this]{link_rel}))[0],
570 @{$class[$this]}{qw(class local_moniker from_cols)},
571 $class[$that]{class},
572 @{$class[$this]}{qw(remote_moniker to_cols)},
574 link_class => $link_class,
575 link_moniker => $link_moniker,
576 link_rel_name => $class[$this]{link_table_rel_name},
580 $class[$this]{m2m_relname} = $self->_resolve_relname_collision(
581 @{$class[$this]}{qw(local_moniker from_cols m2m_relname)},
585 for my $this (0, 1) {
586 my $that = $this ? 0 : 1;
588 push @{$all_code->{$class[$this]{class}}}, {
589 method => 'many_to_many',
591 @{$class[$this]}{qw(m2m_relname link_table_rel_name link_rel)},
592 $self->_relationship_attrs('many_to_many', {}, {
593 rel_type => 'many_to_many',
594 rel_name => $class[$this]{class2_relname},
595 local_source => $self->schema->source($class[$this]{local_moniker}),
596 remote_source => $self->schema->source($class[$this]{remote_moniker}),
597 local_table => $self->loader->class_to_table->{$class[$this]{class}},
598 local_cols => $class[$this]{from_cols},
599 remote_table => $self->loader->class_to_table->{$class[$that]{class}},
600 remote_cols => $class[$that]{from_cols},
604 local_class => $class[$this]{class},
605 link_class => $link_class,
606 local_moniker => $class[$this]{local_moniker},
607 remote_moniker => $class[$this]{remote_moniker},
615 my ($self, $rels) = @_;
617 my @rels = map [ $_->{args}[0] => $_ ], @$rels;
619 $rel_names{$_}++ foreach map $_->[0], @rels;
621 my @dups = grep $rel_names{$_} > 1, keys %rel_names;
625 foreach my $dup (@dups) {
626 $dups{$dup} = [ map $_->[1], grep { $_->[0] eq $dup } @rels ];
637 $self->__tagger(Lingua::EN::Tagger->new) unless $self->__tagger;
639 return $self->__tagger;
643 my ($self, @cols) = @_;
647 foreach my $col (@cols) {
648 my @words = split_name $col;
650 my $tagged = $self->_tagger->get_readable(join ' ', @words);
652 push @adjectives, $tagged =~ m{\G(\w+)/JJ\s+}g;
658 sub _name_to_identifier {
659 my ($self, $name) = @_;
661 my $to_identifier = $self->loader->naming->{force_ascii} ?
662 \&String::ToIdentifier::EN::to_identifier
663 : \&String::ToIdentifier::EN::Unicode::to_identifier;
665 return join '_', map lc, split_name $to_identifier->($name, '_');
669 my ($self, $all_code, $in_class, $dups) = @_;
671 DUP: foreach my $dup (keys %$dups) {
672 my @rels = @{ $dups->{$dup} };
674 # Check if there are rels to the same table name in different
675 # schemas/databases, if so qualify them.
676 my @tables = map $self->loader->moniker_to_table->{$_->{extra}{remote_moniker}},
679 # databases are different, prepend database
680 if ($tables[0]->can('database') && (uniq map $_->database||'', @tables) > 1) {
681 # If any rels are in the same database, we have to distinguish by
682 # both schema and database.
684 $db_counts{$_}++ for map $_->database, @tables;
685 my $use_schema = any { $_ > 1 } values %db_counts;
687 foreach my $i (0..$#rels) {
689 my $table = $tables[$i];
691 $rel->{args}[0] = $self->_name_to_identifier($table->database)
692 . ($use_schema ? ('_' . $self->name_to_identifier($table->schema)) : '')
693 . '_' . $rel->{args}[0];
697 # schemas are different, prepend schema
698 elsif ((uniq map $_->schema||'', @tables) > 1) {
699 foreach my $i (0..$#rels) {
701 my $table = $tables[$i];
703 $rel->{args}[0] = $self->_name_to_identifier($table->schema)
704 . '_' . $rel->{args}[0];
709 foreach my $rel (@rels) {
710 next if $rel->{method} =~ /^(?:belongs_to|many_to_many)\z/;
712 my @to_cols = apply { s/^foreign\.//i }
713 keys %{ $rel->{args}[2] };
715 my @adjectives = $self->_adjectives(@to_cols);
717 # If there are no adjectives, and there is only one might_have
718 # rel to that class, we hardcode 'active'.
720 my $to_class = $rel->{args}[1];
722 if ((not @adjectives)
723 && (grep { $_->{method} eq 'might_have'
724 && $_->{args}[1] eq $to_class } @{ $all_code->{$in_class} }) == 1) {
726 @adjectives = 'active';
730 my $rel_name = join '_', sort(@adjectives), $rel->{args}[0];
732 ($rel_name) = $rel->{method} eq 'might_have' ?
733 $self->_inflect_singular($rel_name)
735 $self->_inflect_plural($rel_name);
737 my ($local_class, $local_moniker, $remote_moniker)
739 {qw/local_class local_moniker remote_moniker/};
741 my @from_cols = apply { s/^self\.//i }
742 values %{ $rel->{args}[2] };
744 ($rel_name) = $self->_rel_name_map($rel_name, $rel->{method}, $local_class, $local_moniker, \@from_cols, $to_class, $remote_moniker, \@to_cols);
746 $rel_name = $self->_resolve_relname_collision($local_moniker, \@from_cols, $rel_name);
748 $rel->{args}[0] = $rel_name;
753 # Check again for duplicates, since the heuristics above may not have resolved them all.
755 if ($dups = $self->_duplicates($all_code->{$in_class})) {
756 foreach my $dup (keys %$dups) {
758 my @rels = map $_->[1], sort { $a->[0] <=> $b->[0] } map [
764 }->{$_->{method}}, $_
765 ], @{ $dups->{$dup} };
769 foreach my $rel (@rels[1 .. $#rels]) {
770 my $inflect_type = $rel->{method} =~ /^(?:many_to_many|has_many)\z/ ?
775 my $inflect_method = "_$inflect_type";
777 my $relname_new_uninflected = $rel->{args}[0] . "_$rel_num";
781 my ($local_class, $local_moniker, $remote_moniker)
783 {qw/local_class local_moniker remote_moniker/};
785 my (@from_cols, @to_cols, $to_class);
787 if ($rel->{method} eq 'many_to_many') {
788 @from_cols = apply { s/^self\.//i } values %{
789 (first { $_->{args}[0] eq $rel->{args}[1] } @{ $all_code->{$local_class} })
792 @to_cols = apply { s/^foreign\.//i } keys %{
793 (first { $_->{args}[0] eq $rel->{args}[2] }
794 @{ $all_code->{ $rel->{extra}{link_class} } })
797 $to_class = $self->schema->source($remote_moniker)->result_class;
800 @from_cols = apply { s/^self\.//i } values %{ $rel->{args}[2] };
801 @to_cols = apply { s/^foreign\.//i } keys %{ $rel->{args}[2] };
802 $to_class = $rel->{args}[1];
805 my ($relname_new, $inflect_mapped) =
806 $self->$inflect_method($relname_new_uninflected);
810 ($relname_new, $rel_name_mapped) = $self->_rel_name_map($relname_new, $rel->{method}, $local_class, $local_moniker, \@from_cols, $to_class, $remote_moniker, \@to_cols);
812 my $mapped = $inflect_mapped || $rel_name_mapped;
814 warn <<"EOF" unless $mapped;
815 Could not find a proper name for relationship '$relname_new' in source
816 '$local_moniker' for columns '@{[ join ',', @from_cols ]}'. Supply a value in
817 '$inflect_type' for '$relname_new_uninflected' or 'rel_name_map' for
818 '$relname_new' to name this relationship.
821 $relname_new = $self->_resolve_relname_collision($local_moniker, \@from_cols, $relname_new);
823 $rel->{args}[0] = $relname_new;
829 sub _relnames_and_method {
830 my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_;
832 my $remote_moniker = $rel->{remote_source};
833 my $remote_obj = $self->schema->source( $remote_moniker );
834 my $remote_class = $self->schema->class( $remote_moniker );
835 my $local_relname = $self->_local_relname( $rel->{remote_table}, $cond);
837 my $local_cols = $rel->{local_columns};
838 my $local_table = $rel->{local_table};
839 my $local_class = $self->schema->class($local_moniker);
840 my $local_source = $self->schema->source($local_moniker);
842 my $remote_relname_uninflected = $self->_normalize_name($local_table);
843 my ($remote_relname) = $self->_inflect_plural($self->_normalize_name($local_table));
845 my $remote_method = 'has_many';
847 # If the local columns have a UNIQUE constraint, this is a one-to-one rel
848 if (array_eq([ $local_source->primary_columns ], $local_cols) ||
849 first { array_eq($_->[1], $local_cols) } @$uniqs) {
850 $remote_method = 'might_have';
851 ($remote_relname) = $self->_inflect_singular($remote_relname_uninflected);
854 # If more than one rel between this pair of tables, use the local
855 # col names to distinguish, unless the rel was created previously.
856 if ($counters->{$remote_moniker} > 1) {
857 my $relationship_exists = 0;
859 if (-f (my $existing_remote_file = $self->loader->get_dump_filename($remote_class))) {
860 my $class = "${remote_class}Temporary";
862 if (not Class::Inspector->loaded($class)) {
863 my $code = slurp_file $existing_remote_file;
865 $code =~ s/(?<=package $remote_class)/Temporary/g;
867 $code =~ s/__PACKAGE__->meta->make_immutable[^;]*;//g;
872 push @{ $self->_temp_classes }, $class;
875 if ($class->has_relationship($remote_relname)) {
876 my $rel_cols = [ sort { $a cmp $b } apply { s/^foreign\.//i }
877 (keys %{ $class->relationship_info($remote_relname)->{cond} }) ];
879 $relationship_exists = 1 if array_eq([ sort @$local_cols ], $rel_cols);
883 if (not $relationship_exists) {
884 my $colnames = q{_} . $self->_normalize_name(join '_', @$local_cols);
885 $local_relname .= $colnames if keys %$cond > 1;
887 $remote_relname = $self->_strip_id_postfix($self->_normalize_name($local_table . $colnames));
889 $remote_relname_uninflected = $remote_relname;
890 ($remote_relname) = $self->_inflect_plural($remote_relname);
892 # if colnames were added and this is a might_have, re-inflect
893 if ($remote_method eq 'might_have') {
894 ($remote_relname) = $self->_inflect_singular($remote_relname_uninflected);
899 return ($local_relname, $remote_relname, $remote_method);
903 my ($self, $relname, $method, $local_class, $local_moniker, $local_cols,
904 $remote_class, $remote_moniker, $remote_cols, $extra) = @_;
910 local_class => $local_class,
911 local_moniker => $local_moniker,
912 local_columns => $local_cols,
913 remote_class => $remote_class,
914 remote_moniker => $remote_moniker,
915 remote_columns => $remote_cols,
918 $self->_run_user_map($self->rel_name_map, $info);
922 my ($self, $map, $info) = @_;
924 my $new_name = $info->{name};
927 if ('HASH' eq ref($map)) {
928 my $name = $info->{name};
929 my $moniker = $info->{local_moniker};
930 if ($map->{$moniker} and 'HASH' eq ref($map->{$moniker})
931 and $map->{$moniker}{$name}
933 $new_name = $map->{$moniker}{$name};
936 elsif ($map->{$name} and not 'HASH' eq ref($map->{$name})) {
937 $new_name = $map->{$name};
941 elsif ('CODE' eq ref($map)) {
944 croak "reentered rel_name_map must be a hashref"
945 unless 'HASH' eq ref($cb_map);
946 my ($cb_name, $cb_mapped) = $self->_run_user_map($cb_map, $info);
947 return $cb_mapped && $cb_name;
949 my $name = $map->($info, $cb);
956 return ($new_name, $mapped);
962 for my $class (@{ $self->_temp_classes }) {
963 Class::Unload->unload($class);
966 $self->_temp_classes([]);
971 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
975 This library is free software; you can redistribute it and/or modify it under
976 the same terms as Perl itself.
981 # vim:et sts=4 sw=4 tw=0: