1 package # hide from PAUSE
2 DBIx::Class::Relationship::HasMany;
9 our %_pod_inherit_config =
11 class_map => { 'DBIx::Class::Relationship::HasMany' => 'DBIx::Class::Relationship' }
15 my ($class, $rel, $f_class, $cond, $attrs) = @_;
18 $class->ensure_class_loaded($f_class);
19 my ($pri, $too_many) = try { $class->_pri_cols }
21 $class->throw_exception("Can't infer join condition for ${rel} on ${class}: $_");
24 $class->throw_exception(
25 "has_many can only infer join for a single primary key; ".
29 $class->throw_exception(
30 "has_many needs a primary key to infer a join; ".
32 ) if !defined $pri && (!defined $cond || !length $cond);
35 if (defined $cond && length $cond) {
37 $guess = "caller specified foreign key '$f_key'";
39 $class =~ /([^\:]+)$/;
40 $f_key = lc $1; # go ahead and guess; best we can do
41 $guess = "using our class name '$class' as foreign key";
44 my $f_class_loaded = try { $f_class->columns };
45 $class->throw_exception(
46 "No such column ${f_key} on foreign class ${f_class} ($guess)"
47 ) if $f_class_loaded && !$f_class->has_column($f_key);
49 $cond = { "foreign.${f_key}" => "self.${pri}" };
52 my $default_cascade = ref $cond eq 'CODE' ? 0 : 1;
54 $class->add_relationship($rel, $f_class, $cond, {
57 cascade_delete => $default_cascade,
58 cascade_copy => $default_cascade,