1 package # hide from PAUSE
2 DBIx::Class::Relationship::BelongsTo;
4 # Documentation for these methods can be found in
5 # DBIx::Class::Relationship
12 our %_pod_inherit_config =
14 class_map => { 'DBIx::Class::Relationship::BelongsTo' => 'DBIx::Class::Relationship' }
18 my ($class, $rel, $f_class, $cond, $attrs) = @_;
20 # assume a foreign key constraint unless defined otherwise
21 $attrs->{is_foreign_key_constraint} = 1
22 if not exists $attrs->{is_foreign_key_constraint};
23 $attrs->{undef_on_null_fk} = 1
24 if not exists $attrs->{undef_on_null_fk};
26 # no join condition or just a column name
30 if (defined $cond and length $cond) {
32 $guess = "caller specified foreign key '$f_key'";
36 $guess = "using given relationship name '$rel' as foreign key column name";
39 $class->throw_exception(
40 "No such column '$f_key' declared yet on ${class} ($guess)"
41 ) unless $class->has_column($f_key);
43 $class->ensure_class_loaded($f_class);
45 $f_class->result_source_instance;
48 $class->throw_exception(
49 "Foreign class '$f_class' does not seem to be a Result class "
50 . "(or it simply did not load entirely due to a circular relation chain)"
54 my $pri = $f_rsrc->_single_pri_col_or_die;
56 $cond = { "foreign.${pri}" => "self.${f_key}" };
59 # explicit join condition
61 if (ref $cond eq 'HASH') { # ARRAY is also valid
64 if (m/\./) { # Explicit join condition
68 $cond_rel->{"foreign.$_"} = "self.".$cond->{$_};
79 (keys %$cond)[0] =~ /^foreign\./
81 $class->has_column($rel)
82 ) ? 'filter' : 'single';
84 my $fk_columns = ($acc_type eq 'single' and ref $cond eq 'HASH')
85 ? { map { $_ =~ /^self\.(.+)/ ? ( $1 => 1 ) : () } (values %$cond ) }
89 $class->add_relationship($rel, $f_class,
93 accessor => $acc_type,
94 $fk_columns ? ( fk_columns => $fk_columns ) : (),
102 # Attempt to remove the POD so it (maybe) falls off the indexer
106 #Alexander Hartmaier <Alexander.Hartmaier@t-systems.at>
108 #Matt S. Trout <mst@shadowcatsystems.co.uk>