From: Peter Rabbitson Date: Wed, 11 Jun 2014 11:15:02 +0000 (+0200) Subject: Adjust error messages - joinfrees can be returned from noncode rels X-Git-Tag: v0.082800~181 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1daf13637feee7722e7bbaddb608920c9f8fd1df;p=dbsrgits%2FDBIx-Class.git Adjust error messages - joinfrees can be returned from noncode rels --- diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index cf82677..a924b7e 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -640,7 +640,7 @@ sub new_related { $rel_info->{cond}, $rel, $self, $rel ); - $self->throw_exception("Custom relationship '$rel' does not resolve to a join-free condition fragment") + $self->throw_exception("Relationship '$rel' does not resolve to a join-free condition fragment") if $crosstable; if ( @@ -819,7 +819,7 @@ sub set_from_related { my ($cond, $crosstable, $nonequality_foreign_columns) = $rsrc->_resolve_condition ( $rel_info->{cond}, $f_obj, $rel, $rel ); - $self->throw_exception("Custom relationship '$rel' does not resolve to a join-free condition fragment") + $self->throw_exception("Relationship '$rel' does not resolve to a join-free condition fragment") if $crosstable; $self->throw_exception(sprintf ( diff --git a/lib/DBIx/Class/Relationship/ManyToMany.pm b/lib/DBIx/Class/Relationship/ManyToMany.pm index ef63b08..8237602 100644 --- a/lib/DBIx/Class/Relationship/ManyToMany.pm +++ b/lib/DBIx/Class/Relationship/ManyToMany.pm @@ -138,7 +138,7 @@ EOW ); $self->throw_exception( - "Custom relationship '$rel' does not resolve to a join-free condition, " + "Relationship '$rel' does not resolve to a join-free condition, " ."unable to use with the ManyToMany helper '$f_rel'" ) if $crosstable; diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index ca8a23e..37ef6cb 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -773,11 +773,15 @@ sub find { next if $keyref eq 'ARRAY'; # has_many for multi_create - my $rel_q = $rsrc->_resolve_condition( + my ($rel_cond, $crosstable) = $rsrc->_resolve_condition( $relinfo->{cond}, $val, $key, $key ); - die "Can't handle complex relationship conditions in find" if ref($rel_q) ne 'HASH'; - @related{keys %$rel_q} = values %$rel_q; + + $self->throw_exception("Complex condition via relationship '$key' is unsupported in find()") + if $crosstable or ref($rel_cond) ne 'HASH'; + + # supplement + @related{keys %$rel_cond} = values %$rel_cond; } } diff --git a/t/relationship/custom.t b/t/relationship/custom.t index 61f709c..0cf32b5 100644 --- a/t/relationship/custom.t +++ b/t/relationship/custom.t @@ -177,7 +177,7 @@ is( # try a specific everything via a non-simplified rel throws_ok { $artist->create_related('cds_90s', { title => 'related_creation 4', year => '2038' }); -} qr/\QCustom relationship 'cds_90s' does not resolve to a join-free condition fragment/, +} qr/\QRelationship 'cds_90s' does not resolve to a join-free condition fragment/, 'Create failed - non-simplified rel'; # Do a self-join last-entry search