X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRelationship%2FAccessor.pm;h=6ec2f258cd0c555280b7f8be829a13a3100a3ded;hb=6ffb5be522e752ea1ad2a99d36648535fe30a43b;hp=76183deac2a5b22a37d72c8dc766599b5dd43284;hpb=e60dc79fcd4d6318e83584b826526e65048b86a9;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Relationship/Accessor.pm b/lib/DBIx/Class/Relationship/Accessor.pm index 76183de..6ec2f25 100644 --- a/lib/DBIx/Class/Relationship/Accessor.pm +++ b/lib/DBIx/Class/Relationship/Accessor.pm @@ -3,6 +3,8 @@ package # hide from PAUSE use strict; use warnings; +use Sub::Name (); +use Class::Inspector (); sub register_relationship { my ($class, $rel, $info) = @_; @@ -16,6 +18,7 @@ sub add_relationship_accessor { my ($class, $rel, $acc_type) = @_; my %meth; if ($acc_type eq 'single') { + my $rel_info = $class->relationship_info($rel); $meth{$rel} = sub { my $self = shift; if (@_) { @@ -24,6 +27,13 @@ sub add_relationship_accessor { } elsif (exists $self->{_relationship_data}{$rel}) { return $self->{_relationship_data}{$rel}; } else { + my $cond = $self->result_source->resolve_condition( + $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; + } my $val = $self->find_related($rel, {}, {}); return unless $val; return $self->{_relationship_data}{$rel} = $val; @@ -57,7 +67,8 @@ sub add_relationship_accessor { no strict 'refs'; no warnings 'redefine'; foreach my $meth (keys %meth) { - *{"${class}::${meth}"} = $meth{$meth}; + my $name = join '::', $class, $meth; + *$name = Sub::Name::subname($name, $meth{$meth}); } } }