There is no point of ordering the insides of a complex prefetch without a limit
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Row.pm
index d88edc2..bdc7aee 100644 (file)
@@ -1186,8 +1186,27 @@ sub inflate_result {
     for my $pre ( keys %$prefetch ) {
 
       my @pre_objects;
-      if (@{$prefetch->{$pre}||[]}) {
-        my $pre_source = $source->related_source($pre);
+      if (
+        @{$prefetch->{$pre}||[]}
+          and
+        ref($prefetch->{$pre}) ne $DBIx::Class::ResultSource::RowParser::Util::null_branch_class
+      ) {
+        my $pre_source = try {
+          $source->related_source($pre)
+        } catch {
+          my $err = sprintf
+            "Inflation into non-existent relationship '%s' of '%s' requested",
+            $pre,
+            $source->source_name,
+          ;
+          if (my ($colname) = sort { length($a) <=> length ($b) } keys %{$prefetch->{$pre}[0] || {}} ) {
+            $err .= sprintf ", check the inflation specification (columns/as) ending in '...%s.%s'",
+            $pre,
+            $colname,
+          }
+
+          $source->throw_exception($err);
+        };
 
         @pre_objects = map {
           $pre_source->result_class->inflate_result( $pre_source, @$_ )