1 package # hide from PAUSE
2 DBIx::Class::Relationship::HasMany;
7 our %_pod_inherit_config =
9 class_map => { 'DBIx::Class::Relationship::HasMany' => 'DBIx::Class::Relationship' }
13 my ($class, $rel, $f_class, $cond, $attrs) = @_;
16 $class->ensure_class_loaded($f_class);
17 my ($pri, $too_many) = eval { $class->_pri_cols };
18 $class->throw_exception(
19 "Can't infer join condition for ${rel} on ${class}: $@"
22 $class->throw_exception(
23 "has_many can only infer join for a single primary key; ".
27 $class->throw_exception(
28 "has_many needs a primary key to infer a join; ".
30 ) if !defined $pri && (!defined $cond || !length $cond);
33 if (defined $cond && length $cond) {
35 $guess = "caller specified foreign key '$f_key'";
37 $class =~ /([^\:]+)$/;
38 $f_key = lc $1; # go ahead and guess; best we can do
39 $guess = "using our class name '$class' as foreign key";
42 my $f_class_loaded = eval { $f_class->columns };
43 $class->throw_exception(
44 "No such column ${f_key} on foreign class ${f_class} ($guess)"
45 ) if $f_class_loaded && !$f_class->has_column($f_key);
47 $cond = { "foreign.${f_key}" => "self.${pri}" };
50 $class->add_relationship($rel, $f_class, $cond, {