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;
20 $class->throw_exception(
21 "might_have/has_one can only infer join for a single primary key; ".
24 my $f_class_loaded = eval { $f_class->columns };
26 if (defined $cond && length $cond) {
28 $guess = "caller specified foreign key '$f_key'";
29 } elsif ($f_class_loaded && $f_class->has_column($rel)) {
31 $guess = "using given relationship '$rel' for foreign key";
33 ($f_key, $too_many) = $f_class->primary_columns;
34 $class->throw_exception(
35 "might_have/has_one can only infer join for a single primary key; ".
38 $guess = "using primary key of foreign class for foreign key";
40 $class->throw_exception(
41 "No such column ${f_key} on foreign class ${f_class} ($guess)"
42 ) if $f_class_loaded && !$f_class->has_column($f_key);
43 $cond = { "foreign.${f_key}" => "self.${pri}" };
45 $class->add_relationship($rel, $f_class,
47 { accessor => 'single',
48 cascade_update => 1, cascade_delete => 1,
49 ($join_type ? ('join_type' => $join_type) : ()),