make set_from_related handle undef
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Relationship / Base.pm
index 9ea8cff..96b7c18 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 
 use base qw/DBIx::Class/;
 
-=head1 NAME 
+=head1 NAME
 
 DBIx::Class::Relationship::Base - Inter-table relationships
 
@@ -15,7 +15,7 @@ DBIx::Class::Relationship::Base - Inter-table relationships
 
 This class provides methods to describe the relationships between the
 tables in your database model. These are the "bare bones" relationships
-methods, for predefined ones, look in L<DBIx::Class::Relationship>. 
+methods, for predefined ones, look in L<DBIx::Class::Relationship>.
 
 =head1 METHODS
 
@@ -23,7 +23,7 @@ methods, for predefined ones, look in L<DBIx::Class::Relationship>.
 
 =over 4
 
-=item Arguments: ('relname', 'Foreign::Class', $cond, $attrs)
+=item Arguments: 'relname', 'Foreign::Class', $cond, $attrs
 
 =back
 
@@ -31,8 +31,8 @@ methods, for predefined ones, look in L<DBIx::Class::Relationship>.
 
 The condition needs to be an SQL::Abstract-style representation of the
 join between the tables. When resolving the condition for use in a JOIN,
-keys using the psuedo-table I<foreign> are resolved to mean "the Table on the
-other side of the relationship", and values using the psuedo-table I<self>
+keys using the pseudo-table I<foreign> are resolved to mean "the Table on the
+other side of the relationship", and values using the pseudo-table I<self>
 are resolved to mean "the Table this class is representing". Other
 restrictions, such as by value, sub-select and other tables, may also be
 used. Please check your database for JOIN parameter support.
@@ -92,7 +92,7 @@ created, which calls C<create_related> for the relationship.
 
 =over 4
 
-=item Arguments: ($relname, $rel_info)
+=item Arguments: $relname, $rel_info
 
 =back
 
@@ -107,9 +107,9 @@ sub register_relationship { }
 
 =over 4
 
-=item Arguments: ($relationship_name)
+=item Arguments: $relationship_name
 
-=item Returns: $related_resultset
+=item Return Value: $related_resultset
 
 =back
 
@@ -276,9 +276,11 @@ sub set_from_related {
     "condition for $rel is of type ".
     (ref $cond ? ref $cond : 'plain scalar')
   ) unless ref $cond eq 'HASH';
-  my $f_class = $self->result_source->schema->class($rel_obj->{class});
-  $self->throw_exception( "Object $f_obj isn't a ".$f_class )
-    unless $f_obj->isa($f_class);
+  if (defined $f_obj) {
+    my $f_class = $self->result_source->schema->class($rel_obj->{class});
+    $self->throw_exception( "Object $f_obj isn't a ".$f_class )
+      unless $f_obj->isa($f_class);
+  }
   $self->set_columns(
     $self->result_source->resolve_condition(
        $rel_obj->{cond}, $f_obj, $rel));