| 1 | package DBIO::Relationship::HasMany; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Declare a one-to-many relationship | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 378 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 378 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 378 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 378 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 378 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 378 | our %_pod_inherit_config = | |||||||||||||||||||||||||||
| 13 | ( | ||||||||||||||||||||||||||||
| 14 | class_map => { 'DBIO::Relationship::HasMany' => 'DBIO::Relationship' } | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 9514 | ▶ | sub has_many { | ||||||||||||||||||||||||||
|
Subroutine
has_many: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 9514 | my ($class, $rel, $f_class, $cond, $attrs) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 9514 | ▶ | unless (ref $cond) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 5668 | my $pri = $class->result_source_instance->_single_pri_col_or_die; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 5668 | my ($f_key,$guess); | |||||||||||||||||||||||||||
| 26 | 5668 | ▶ | if (defined $cond && length $cond) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cond and length $cond
MC/DC50%1/2
defined $cond and length $cond
defined $cond
length $cond
Truth table66%2/3
A and B
A= defined $condB= length $cond
| |||||||||||||||||||||||||||||
| 27 | 3876 | $f_key = $cond; | |||||||||||||||||||||||||||
| 28 | 3876 | $guess = "caller specified foreign key '$f_key'"; | |||||||||||||||||||||||||||
| 29 | } else { | ||||||||||||||||||||||||||||
| 30 | 1792 | $class =~ /([^\:]+)$/; # match is safe - $class can't be '' | |||||||||||||||||||||||||||
| 31 | 1792 | $f_key = lc $1; # go ahead and guess; best we can do | |||||||||||||||||||||||||||
| 32 | 1792 | $guess = "using our class name '$class' as foreign key source"; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # FIXME - this check needs to be moved to schema-composition time... | ||||||||||||||||||||||||||||
| 36 | # # only perform checks if the far side appears already loaded | ||||||||||||||||||||||||||||
| 37 | # if (my $f_rsrc = try { $f_class->result_source_instance } ) { | ||||||||||||||||||||||||||||
| 38 | # $class->throw_exception( | ||||||||||||||||||||||||||||
| 39 | # "No such column '$f_key' on foreign class ${f_class} ($guess)" | ||||||||||||||||||||||||||||
| 40 | # ) if !$f_rsrc->has_column($f_key); | ||||||||||||||||||||||||||||
| 41 | # } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 5668 | $cond = { "foreign.${f_key}" => "self.${pri}" }; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 9514 | ▶ | my $default_cascade = ref $cond eq 'CODE' ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | $class->add_relationship($rel, $f_class, $cond, { | ||||||||||||||||||||||||||||
| 49 | accessor => 'multi', | ||||||||||||||||||||||||||||
| 50 | join_type => 'LEFT', | ||||||||||||||||||||||||||||
| 51 | cascade_delete => $default_cascade, | ||||||||||||||||||||||||||||
| 52 | cascade_copy => $default_cascade, | ||||||||||||||||||||||||||||
| 53 | is_depends_on => 0, | ||||||||||||||||||||||||||||
| 54 | 9514 | ▶ | %{$attrs||{}} | ||||||||||||||||||||||||||
|
Condition100%2/2
$attrs || {}
MC/DC100%1/1
$attrs || {}
$attrs
Truth table100%2/2
A
A= $attrs
| |||||||||||||||||||||||||||||
| 55 | }); | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 378 | 1; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||