1 package # hide from PAUSE
2 DBIx::Class::Relationship::HasMany;
8 my ($class, $rel, $f_class, $cond, $attrs) = @_;
10 eval "require $f_class";
12 $class->throw_exception($@) unless $@ =~ /Can't locate/;
16 my ($pri, $too_many) = $class->primary_columns;
17 $class->throw_exception( "has_many can only infer join for a single primary key; ${class} has more" )
21 if (defined $cond && length $cond) {
23 $guess = "caller specified foreign key '$f_key'";
25 $class =~ /([^\:]+)$/;
26 $f_key = lc $1; # go ahead and guess; best we can do
27 $guess = "using our class name '$class' as foreign key";
30 my $f_class_loaded = eval { $f_class->columns };
31 $class->throw_exception("No such column ${f_key} on foreign class ${f_class} ($guess)")
32 if $f_class_loaded && !$f_class->has_column($f_key);
34 $cond = { "foreign.${f_key}" => "self.${pri}" };
37 $class->add_relationship($rel, $f_class, $cond,
38 { accessor => 'multi',