1 package DBIx::Class::Relationship::BelongsTo;
7 my ($class, $rel, $f_class, $cond, $attrs) = @_;
8 eval "require $f_class";
10 $class->throw($@) unless $@ =~ /Can't locate/;
14 $f_primaries{$_} = 1 for eval { $f_class->primary_columns };
16 # single key relationship
17 if (not defined $cond) {
18 $class->throw("Can't infer join condition for ${rel} on ${class}; unable to load ${f_class}") unless $f_loaded;
19 my ($pri, $too_many) = keys %f_primaries;
20 $class->throw("Can't infer join condition for ${rel} on ${class}; ${f_class} has multiple primary key") if $too_many;
21 $class->throw("Can't find any primary keys for $f_class, try adding some") if !$pri;
22 my $acc_type = ($class->has_column($rel)) ? 'filter' : 'single';
23 $class->add_relationship($rel, $f_class,
24 { "foreign.${pri}" => "self.${rel}" },
25 { accessor => $acc_type, %{$attrs || {}} }
28 # multiple key relationship
32 if (m/\./) { # Explicit join condition
36 $cond_rel->{"foreign.$_"} = "self.".$cond->{$_};
38 $class->add_relationship($rel, $f_class,
40 { accessor => 'single', %{$attrs || {}} }
48 Alexander Hartmaier <Alexander.Hartmaier@t-systems.at>
50 Matt S. Trout <mst@shadowcatsystems.co.uk>