1 package # hide from PAUSE
2 DBIx::Class::Relationship::HasOne;
8 shift->_has_one('LEFT' => @_);
12 shift->_has_one(undef() => @_);
16 my ($class, $join_type, $rel, $f_class, $cond, $attrs) = @_;
18 $class->ensure_class_loaded($f_class);
19 my ($pri, $too_many) = $class->primary_columns;
21 $class->throw_exception(
22 "might_have/has_one can only infer join for a single primary key; ".
26 $class->throw_exception(
27 "might_have/has_one needs a primary key to infer a join; ".
29 ) if !defined $pri && (!defined $cond || !length $cond);
31 my $f_class_loaded = eval { $f_class->columns };
33 if (defined $cond && length $cond) {
35 $guess = "caller specified foreign key '$f_key'";
36 } elsif ($f_class_loaded && $f_class->has_column($rel)) {
38 $guess = "using given relationship '$rel' for foreign key";
40 ($f_key, $too_many) = $f_class->primary_columns;
41 $class->throw_exception(
42 "might_have/has_one can only infer join for a single primary key; ".
45 $guess = "using primary key of foreign class for foreign key";
47 $class->throw_exception(
48 "No such column ${f_key} on foreign class ${f_class} ($guess)"
49 ) if $f_class_loaded && !$f_class->has_column($f_key);
50 $cond = { "foreign.${f_key}" => "self.${pri}" };
52 $class->add_relationship($rel, $f_class,
54 { accessor => 'single',
55 cascade_update => 1, cascade_delete => 1,
56 ($join_type ? ('join_type' => $join_type) : ()),