Modify the null-branch pruning introduced in ce556881, restore compat
[dbsrgits/DBIx-Class.git] / t / prefetch / incomplete.t
index 781c1e1..cf6c514 100644 (file)
@@ -2,6 +2,7 @@ use strict;
 use warnings;
 
 use Test::More;
+use Test::Deep;
 use Test::Exception;
 use lib qw(t/lib);
 use DBICTest;
@@ -9,18 +10,18 @@ use DBICTest;
 my $schema = DBICTest->init_schema();
 
 lives_ok(sub {
-  # while cds.* will be selected anyway (prefetch currently forces the result of _resolve_prefetch)
-  # only the requested me.name/me.artistid columns will be fetched.
+  # while cds.* will be selected anyway (prefetch implies it)
+  # only the requested me.name column will be fetched.
 
   # reference sql with select => [...]
-  #   SELECT me.name, cds.title, me.artistid, cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track FROM ...
+  #   SELECT me.name, cds.title, cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track FROM ...
 
   my $rs = $schema->resultset('Artist')->search(
     { 'cds.title' => { '!=', 'Generic Manufactured Singles' } },
     {
       prefetch => [ qw/ cds / ],
       order_by => [ { -desc => 'me.name' }, 'cds.title' ],
-      select => [qw/ me.name cds.title me.artistid / ],
+      select => [qw/ me.name cds.title / ],
     },
   );
 
@@ -41,7 +42,7 @@ lives_ok ( sub {
   );
   my $years = [qw/ 2001 2001 1999 1998 1997/];
 
-  is_deeply (
+  cmp_deeply (
     [ $rs->search->get_column('me.year')->all ],
     $years,
     'Expected years (at least one duplicate)',
@@ -67,13 +68,13 @@ lives_ok ( sub {
     push @pref_cds_and_tracks, $data;
   }
 
-  is_deeply (
+  cmp_deeply (
     \@pref_cds_and_tracks,
     \@cds_and_tracks,
     'Correct collapsing on non-unique primary object'
   );
 
-  is_deeply (
+  cmp_deeply (
     [ $pref_rs->search ({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' })->all ],
     \@cds_and_tracks,
     'Correct HRI collapsing on non-unique primary object'
@@ -105,8 +106,23 @@ throws_ok(
   sub {
     $schema->resultset('Track')->search({}, { join => { cd => 'artist' }, '+columns' => 'artist.name' } )->next;
   },
-  qr|\QCan't inflate prefetch into non-existent relationship 'artist' from 'Track', check the inflation specification (columns/as) ending in '...artist.name'|,
+  qr|\QInflation into non-existent relationship 'artist' of 'Track' requested, check the inflation specification (columns/as) ending in '...artist.name'|,
   'Sensible error message on mis-specified "as"',
 );
 
+# check complex limiting prefetch without the join-able columns
+{
+  my $pref_rs = $schema->resultset('Owners')->search({}, {
+    rows => 3,
+    offset => 1,
+    columns => 'name',  # only the owner name, still prefetch all the books
+    prefetch => 'books',
+  });
+
+  lives_ok {
+    is ($pref_rs->all, 1, 'Expected count of objects on limtied prefetch')
+  } "Complex limited prefetch works with non-selected join condition";
+}
+
+
 done_testing;