File Coverage

blib/lib/Rose/Planter/ConventionManager.pm
Criterion Covered Total %
statement 14 14 100.0
branch 1 2 50.0
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 19 20 95.0


line stmt bran cond sub pod time code
1             package Rose::Planter::ConventionManager;
2              
3             =head1 NAME
4              
5             Rose::Planter::ConventionManager - some handy convention defaults
6              
7             =head1 DESCRIPTION
8              
9             This is a subclass of Rose::DB::Object::ConventionManager with
10             a few tweaks.
11              
12             =head1 METHODS
13              
14             =cut
15              
16 2     2   11 use base 'Rose::DB::Object::ConventionManager';
  2         4  
  2         198  
17              
18 2     2   11 use strict;
  2         5  
  2         256  
19              
20             =head2 auto_relationship_name_one_to_many
21              
22             By default if "foo_params" is a child of a table "foo",
23             we remove the the "foo_" portion from "foo_params".
24              
25             i.e. If this table has only _one_ foreign key and the table name
26             referred to in the foreign key is a prefix of this table name plus
27             an underscore, then remove the table name and the underscore. Got it?
28              
29             =cut
30              
31             sub auto_relationship_name_one_to_many {
32 1     1 1 193 my $self = shift;
33 1         3 my ($table,$class) = @_;
34 1         9 my $name = $self->SUPER::auto_relationship_name_one_to_many(@_);
35              
36 1         110 my @fks = $class->meta->foreign_keys;
37 1 50       15 return $name unless @fks==1;
38              
39 1         7 my $target = $fks[0]->class->meta->table;
40              
41 1         23 $name =~ s/^$target\_//;
42              
43 1         5 return $name;
44             }
45              
46             1;
47