Properly returb undef/null on single rewlationship accessor
Peter Rabbitson [Wed, 11 Mar 2009 23:23:18 +0000 (23:23 +0000)]
lib/DBIx/Class/Relationship/Accessor.pm

index 02f7db5..065cf69 100644 (file)
@@ -31,17 +31,11 @@ sub add_relationship_accessor {
           $rel_info->{cond}, $rel, $self
         );
         if ($rel_info->{attrs}->{undef_on_null_fk}){
-          return unless ref($cond) eq 'HASH';
-          return if grep { not defined } values %$cond;
+          return undef unless ref($cond) eq 'HASH';
+          return undef if grep { not defined $_ } values %$cond;
         }
         my $val = $self->find_related($rel, {}, {});
-
-        # this really should have been:
-        # return $val unless $val
-        # however someone might already be relying on return() as in:
-        # my @things = map { $_->might_have_acc } ($rs->all)
-        # thus keeping the quirky behavior
-        return unless defined $val;
+        return $val unless $val;  # $val instead of undef so that null-objects can go through
 
         return $self->{_relationship_data}{$rel} = $val;
       }