1 package DBIx::Class::Relationship::BelongsTo;
7 my ($class, $rel, $f_class, $cond, $attrs) = @_;
8 eval "require $f_class";
9 my %f_primaries = eval { %{ $f_class->_primaries } };
11 # single key relationship
12 if (not defined $cond) {
13 $class->throw("Can't infer join condition for ${rel} on ${class}; unable to load ${f_class}") unless $f_loaded;
14 my ($pri, $too_many) = keys %f_primaries;
15 $class->throw("Can't infer join condition for ${rel} on ${class}; ${f_class} has multiple primary key") if $too_many;
16 my $acc_type = ($class->_columns->{$rel}) ? 'filter' : 'single';
17 $class->add_relationship($rel, $f_class,
18 { "foreign.${pri}" => "self.${rel}" },
19 { accessor => $acc_type, %{$attrs || {}} }
22 # multiple key relationship
26 if (m/\./) { # Explicit join condition
30 $cond_rel->{"foreign.$_"} = "self.".$cond->{$_};
32 $class->add_relationship($rel, $f_class,
34 { accessor => 'single', %{$attrs || {}} }
42 Alexander Hartmaier <Alexander.Hartmaier@t-systems.at>
44 Matt S. Trout <mst@shadowcatsystems.co.uk>