Adjust error messages - joinfrees can be returned from noncode rels
Peter Rabbitson [Wed, 11 Jun 2014 11:15:02 +0000 (13:15 +0200)]
lib/DBIx/Class/Relationship/Base.pm
lib/DBIx/Class/Relationship/ManyToMany.pm
lib/DBIx/Class/ResultSet.pm
t/relationship/custom.t

index cf82677..a924b7e 100644 (file)
@@ -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 (
index ef63b08..8237602 100644 (file)
@@ -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;
 
index ca8a23e..37ef6cb 100644 (file)
@@ -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;
     }
   }
 
index 61f709c..0cf32b5 100644 (file)
@@ -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