Merge 'trunk' into 'table_name_ref'
[dbsrgits/DBIx-Class-Historic.git] / t / prefetch / grouped.t
index b44d701..3db5f9e 100644 (file)
@@ -42,6 +42,9 @@ for ($cd_rs->all) {
     },
   );
 
+  # this used to fuck up ->all, do not remove!
+  ok ($track_rs->first, 'There is stuff in the rs');
+
   is($track_rs->count, 5, 'Prefetched count with groupby');
   is($track_rs->all, 5, 'Prefetched objects with groupby');
 
@@ -50,14 +53,13 @@ for ($cd_rs->all) {
     $schema->storage->debugcb ( sub { $query_cnt++ } );
     $schema->storage->debug (1);
 
-    $track_rs->reset;
     while (my $collapsed_track = $track_rs->next) {
       my $cdid = $collapsed_track->get_column('cd');
       is($collapsed_track->get_column('track_count'), 3, "Correct count of tracks for CD $cdid" );
       ok($collapsed_track->cd->title, "Prefetched title for CD $cdid" );
     }
 
-    is ($query_cnt, 0, 'No queries on prefetched titles');
+    is ($query_cnt, 1, 'Single query on prefetched titles');
     $schema->storage->debugcb (undef);
     $schema->storage->debug ($sdebug);
   }
@@ -75,7 +77,7 @@ for ($cd_rs->all) {
           SELECT me.cd
             FROM track me
             JOIN cd cd ON cd.cdid = me.cd
-          WHERE ( me.cd IN ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) )
+          WHERE ( me.cd IN ( ?, ?, ?, ?, ? ) )
           GROUP BY me.cd
         )
       count_subq
@@ -92,11 +94,11 @@ for ($cd_rs->all) {
           SELECT me.cd, COUNT (me.trackid) AS track_count,
             FROM track me
             JOIN cd cd ON cd.cdid = me.cd
-          WHERE ( me.cd IN ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) )
+          WHERE ( me.cd IN ( ?, ?, ?, ?, ? ) )
           GROUP BY me.cd
           ) as me
         JOIN cd cd ON cd.cdid = me.cd
-      WHERE ( me.cd IN ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) )
+      WHERE ( me.cd IN ( ?, ?, ?, ?, ? ) )
     )',
     [ map { [ 'me.cd' => $_] } ( ($cd_rs->get_column ('cdid')->all) x 2 ) ],
     'next() query generated expected SQL',
@@ -180,7 +182,7 @@ for ($cd_rs->all) {
 
   is ($most_tracks_rs->count, 2, 'Limit works');
   my $top_cd = $most_tracks_rs->first;
-  is ($top_cd->id, 2, 'Correct cd fetched on top'); # 2 because of the slice(1,1) above
+  is ($top_cd->id, 2, 'Correct cd fetched on top'); # 2 because of the slice(1,1) earlier
 
   my $query_cnt = 0;
   $schema->storage->debugcb ( sub { $query_cnt++ } );