[Bast-commits] r6372 - DBIx-Class/0.08/branches/unresolvable_prefetch/t/prefetch

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Fri May 22 09:07:27 GMT 2009


Author: ribasushi
Date: 2009-05-22 09:07:26 +0000 (Fri, 22 May 2009)
New Revision: 6372

Modified:
   DBIx-Class/0.08/branches/unresolvable_prefetch/t/prefetch/unresolvable.t
Log:
Simplify unresolvable test by arcanez

Modified: DBIx-Class/0.08/branches/unresolvable_prefetch/t/prefetch/unresolvable.t
===================================================================
--- DBIx-Class/0.08/branches/unresolvable_prefetch/t/prefetch/unresolvable.t	2009-05-22 08:35:36 UTC (rev 6371)
+++ DBIx-Class/0.08/branches/unresolvable_prefetch/t/prefetch/unresolvable.t	2009-05-22 09:07:26 UTC (rev 6372)
@@ -6,46 +6,35 @@
 use lib qw(t/lib);
 use DBICTest;
 
+plan tests => 5;
+
 my $schema = DBICTest->init_schema();
 
-eval "use DBD::SQLite";
-plan skip_all => 'needs DBD::SQLite for testing' if $@;
-plan tests => 1;
+lives_ok(sub {
 
-=cut
-test fails with select => [ ], when the columns required for the relationship are absent
+#  use Data::Dumper;
+#  warn Dumper [$schema->resultset('Artist')->search ({}, { prefetch => 'cds' })->hri_dump->all];
 
-DBIC_TRACE=1:
 
-  with select => [ qw / me.name cds.title ] (missing columns required for relationships)
+  # while cds.* will be selected anyway (prefetch currently forces the result of _resolve_prefetch)
+  # only the requested me.name column will be fetched. This somehow does work on 08010 (tested)
 
-  SELECT me.name, cds.title, cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track
-  FROM artist me
-  LEFT JOIN cd cds ON cds.artist = me.artistid
-  WHERE ( cds.title != ? )
-  GROUP BY me.name, cds.title
-  ORDER BY me.name, cds.title, cds.artist, cds.year: 'Generic Manufactured Singles'
+  # reference sql with select => [...]
+  #   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 / ],
+    }
+  );
 
-  with no select => [ ]
+  is ($rs->count, 2, 'Correct number of collapsed artists');
+  my $we_are_goth = $rs->first;
+  is ($we_are_goth->name, 'We Are Goth', 'Correct first artist');
+  is ($we_are_goth->cds->count, 1, 'Correct number of CDs for first artist');
+  is ($we_are_goth->cds->first->title, 'Come Be Depressed With Us', 'Correct cd for artist');
 
-  SELECT me.artistid, me.name, me.rank, me.charfield, cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track
-  FROM artist me
-  LEFT JOIN cd cds ON cds.artist = me.artistid 
-  WHERE ( cds.title != ? )
-  GROUP BY me.artistid, me.name, me.rank, me.charfield
-  ORDER BY me.name, cds.title, cds.artist, cds.year: 'Generic Manufactured Singles'
-
-=cut
-
-
-my $rs = $schema->resultset('Artist')->search({ 'cds.title' => { '!=' => 'Generic Manufactured Singles' } }, ## exists
-                                              { prefetch => [ qw/ cds / ],
-                                                join => [ qw/ cds / ],
-                                                select => [ qw/ me.name cds.title / ],
-                                                distinct => 1,
-                                                order_by => [ qw/ me.name cds.title / ],
-                                              });
-
-lives_ok(sub { $rs->first }, 'Lives ok');
+});




More information about the Bast-commits mailing list