Allow accessors type single to return defined but false objects (needed for null...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Relationship / Accessor.pm
index ef38ff8..02f7db5 100644 (file)
@@ -30,12 +30,19 @@ sub add_relationship_accessor {
         my $cond = $self->result_source->resolve_condition(
           $rel_info->{cond}, $rel, $self
         );
-        if( exists $rel_info->{attrs}->{undef_on_null_fk}
-              && $rel_info->{attrs}->{undef_on_null_fk} ){
+        if ($rel_info->{attrs}->{undef_on_null_fk}){
+          return unless ref($cond) eq 'HASH';
           return if grep { not defined } values %$cond;
         }
         my $val = $self->find_related($rel, {}, {});
-        return unless $val;
+
+        # 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 $self->{_relationship_data}{$rel} = $val;
       }
     };