1 package # hide from PAUSE
2 DBIx::Class::Relationship::HasMany;
8 our %_pod_inherit_config =
10 class_map => { 'DBIx::Class::Relationship::HasMany' => 'DBIx::Class::Relationship' }
14 my ($class, $rel, $f_class, $cond, $attrs) = @_;
17 $class->ensure_class_loaded($f_class);
18 my ($pri, $too_many) = try { $class->_pri_cols }
20 $class->throw_exception("Can't infer join condition for ${rel} on ${class}: $_");
23 $class->throw_exception(
24 "has_many can only infer join for a single primary key; ".
28 $class->throw_exception(
29 "has_many needs a primary key to infer a join; ".
31 ) if !defined $pri && (!defined $cond || !length $cond);
34 if (defined $cond && length $cond) {
36 $guess = "caller specified foreign key '$f_key'";
38 $class =~ /([^\:]+)$/;
39 $f_key = lc $1; # go ahead and guess; best we can do
40 $guess = "using our class name '$class' as foreign key";
43 my $f_class_loaded = eval { $f_class->columns };
44 $class->throw_exception(
45 "No such column ${f_key} on foreign class ${f_class} ($guess)"
46 ) if $f_class_loaded && !$f_class->has_column($f_key);
48 $cond = { "foreign.${f_key}" => "self.${pri}" };
51 $class->add_relationship($rel, $f_class, $cond, {