Getting warmer
[dbsrgits/DBIx-Class.git] / t / count / prefetch.t
index 925be3d..654520b 100644 (file)
@@ -7,8 +7,6 @@ use Test::More;
 use DBICTest;
 use DBIC::SqlMakerTest;
 
-plan tests => 14;
-
 my $schema = DBICTest->init_schema();
 
 # collapsing prefetch
@@ -41,16 +39,9 @@ my $schema = DBICTest->init_schema();
 
 # collapsing prefetch with distinct
 {
-  my $first_cd = $schema->resultset('Artist')->first->cds->first;
-  $first_cd->update ({
-    genreid => $first_cd->create_related (
-      genre => ({ name => 'vague genre' })
-    )->id
-  });
-
   my $rs = $schema->resultset("Artist")->search(undef, {distinct => 1})
             ->search_related('cds')->search_related('genre',
-                { 'genre.name' => { '!=', 'foo' } },
+                { 'genre.name' => 'emo' },
                 { prefetch => q(cds) },
             );
   is ($rs->all, 1, 'Correct number of objects');
@@ -62,15 +53,18 @@ my $schema = DBICTest->init_schema();
       SELECT COUNT( * )
         FROM (
           SELECT genre.genreid
-            FROM artist me
+            FROM (
+              SELECT me.artistid, me.name, me.rank, me.charfield
+                FROM artist me GROUP BY me.artistid, me.name, me.rank, me.charfield
+            ) me
             JOIN cd cds ON cds.artist = me.artistid
             JOIN genre genre ON genre.genreid = cds.genreid
             LEFT JOIN cd cds_2 ON cds_2.genreid = genre.genreid
-          WHERE ( genre.name != ? )
-          GROUP BY genre.genreid
-        ) count_subq
+          WHERE ( genre.name = ? ) GROUP BY genre.genreid
+        )
+      count_subq
     )',
-    [ [ 'genre.name' => 'foo' ] ],
+    [ [ 'genre.name' => 'emo' ] ],
   );
 }
 
@@ -78,7 +72,7 @@ my $schema = DBICTest->init_schema();
 {
   my $rs = $schema->resultset("CD")
             ->search_related('tracks',
-                { position => [1,2] },
+                { position => [1,2], 'lyrics.lyric_id' => undef },
                 { prefetch => [qw/disc lyrics/] },
             );
   is ($rs->all, 10, 'Correct number of objects');
@@ -94,47 +88,10 @@ my $schema = DBICTest->init_schema();
         JOIN track tracks ON tracks.cd = me.cdid
         JOIN cd disc ON disc.cdid = tracks.cd
         LEFT JOIN lyrics lyrics ON lyrics.track_id = tracks.trackid
-      WHERE position = ? OR position = ?
+      WHERE lyrics.lyric_id IS NULL AND (position = ? OR position = ?)
     )',
     [ map { [ position => $_ ] } (1, 2) ],
   );
 }
 
-{
-    my $rs = $schema->resultset("Artwork")->search(undef, {distinct => 1})
-              ->search_related('artwork_to_artist')->search_related('artist',
-                 undef,
-                  { prefetch => q(cds) },
-              );
-    is($rs->all, 0, 'failure without WHERE');
-
-    $rs = $schema->resultset("Artwork")->search(undef, {distinct => 1})
-              ->search_related('artwork_to_artist')->search_related('artist',
-                 { 'cds.title' => 'foo' }, # this line has changed
-                  { prefetch => q(cds) },
-              );
-    is($rs->all, 0, 'success with WHERE');
-
-
-    # different case
-    $rs = $schema->resultset("Artist")->search(undef)#, {distinct => 1})
-                ->search_related('cds')->search_related('genre',
-                    { 'genre.name' => 'foo' },
-                    { prefetch => q(cds) },
-                 );
-    is($rs->all, 0, 'success without distinct');
-
-    $rs = $schema->resultset("Artist")->search(undef, {distinct => 1})
-                ->search_related('cds')->search_related('genre',
-                    { 'genre.name' => 'foo' },
-                    #{ prefetch => q(cds) },
-                 );
-    is($rs->all, 0, 'success without prefetch');
-
-    $rs = $schema->resultset("Artist")->search(undef, {distinct => 1})
-                ->search_related('cds')->search_related('genre',
-                    { 'genre.name' => 'foo' },
-                    { prefetch => q(cds) },
-                 );
-    is($rs->all, 0, 'failure with distinct');
-}
+done_testing;