When specifying a prefetch which first converges to a belongs_to and then fans out to multiple has_many's, the collapse code does not work. Attached is a test against 08 trunk.
Index: t/76joins.t
===================================================================
--- t/76joins.t	(revision 4274)
+++ t/76joins.t	(working copy)
@@ -16,7 +16,7 @@
     eval "use DBD::SQLite";
     plan $@
         ? ( skip_all => 'needs DBD::SQLite for testing' )
-        : ( tests => 64 );
+        : ( tests => 66 );
 }
 
 # figure out if we've got a version of sqlite that is older than 3.2.6, in
@@ -469,3 +469,24 @@
   );
 
 is($queries, 0, 'chained search_related after has_many->has_many prefetch ran no queries');
+
+
+# Test again this time with multiple fanning prefetch paths ( M -> 1 -> M & M )
+my $note_rs = $schema->resultset('LinerNotes')->search ({ notes => 'Buy Whiskey!' });
+my $note_rs_pr = $note_rs->search({}, {
+    prefetch => {
+        cd => [qw/tracks tags/]     # <------ this fails
+        #cd => [qw/tracks/]         # <------ this  works
+    },
+});
+
+$queries = 0;
+$schema->storage->debugcb(sub { $queries++ });
+$schema->storage->debug(1);
+
+my $count = $note_rs_pr->first->cd->tracks->count;
+is($queries, 1, 'nested prefetch across many->single->(has_many,has_many) ran exactly 1 query');
+
+my $np_count = $note_rs->first->cd->tracks->count;
+
+is($count, $np_count, 'collapse of results over many->single->(has_many,has_many) prefetch');
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]

Reply via email to