1 package DBIx::Class::Relationship::HasOne;
7 shift->_has_one('LEFT' => @_);
11 shift->_has_one(undef() => @_);
15 my ($class, $join_type, $rel, $f_class, $cond, $attrs) = @_;
16 eval "require $f_class";
18 $class->throw_exception($@) unless $@ =~ /Can't locate/;
22 my ($pri, $too_many) = $class->primary_columns;
23 $class->throw_exception( "might_have/has_one can only infer join for a single primary key; ${class} has more" )
25 my $f_class_loaded = eval { $f_class->columns };
27 if (defined $cond && length $cond) {
29 $guess = "caller specified foreign key '$f_key'";
30 } elsif ($f_class_loaded && $f_class->has_column($rel)) {
32 $guess = "using given relationship '$rel' for foreign key";
34 ($f_key, $too_many) = $f_class->primary_columns;
35 $class->throw_exception( "might_have/has_one can only infer join for a single primary key; ${f_class} has more" )
37 $guess = "using primary key of foreign class for foreign key";
39 $class->throw_exception("No such column ${f_key} on foreign class ${f_class} ($guess)")
40 if $f_class_loaded && !$f_class->has_column($f_key);
41 $cond = { "foreign.${f_key}" => "self.${pri}" };
43 $class->add_relationship($rel, $f_class,
45 { accessor => 'single',
46 cascade_update => 1, cascade_delete => 1,
47 ($join_type ? ('join_type' => $join_type) : ()),