[Bast-commits] r6693 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t/prefetch

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Tue Jun 16 15:23:00 GMT 2009


Author: ribasushi
Date: 2009-06-16 15:22:59 +0000 (Tue, 16 Jun 2009)
New Revision: 6693

Added:
   DBIx-Class/0.08/trunk/t/prefetch/double_prefetch.t
Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
   DBIx-Class/0.08/trunk/t/prefetch/attrs_untouched.t
Log:
Fix possible regression with prefetch select resolution

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-06-16 14:29:41 UTC (rev 6692)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-06-16 15:22:59 UTC (rev 6693)
@@ -2599,19 +2599,21 @@
 
 
   my $collapse = $attrs->{collapse} || {};
+
   if ( my $prefetch = delete $attrs->{prefetch} ) {
     $prefetch = $self->_merge_attr( {}, $prefetch );
-    my @pre_order;
-    foreach my $p ( ref $prefetch eq 'ARRAY' ? @$prefetch : ($prefetch) ) {
 
-      # bring joins back to level of current class
-      my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join});
-      my @prefetch =
-        $source->_resolve_prefetch( $p, $alias, $join_map, \@pre_order, $collapse );
-      push( @{ $attrs->{select} }, map { $_->[0] } @prefetch );
-      push( @{ $attrs->{as} },     map { $_->[1] } @prefetch );
-    }
-    push( @{ $attrs->{order_by} }, @pre_order );
+    my $prefetch_ordering = [];
+
+    my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join});
+
+    my @prefetch =
+      $source->_resolve_prefetch( $prefetch, $alias, $join_map, $prefetch_ordering, $collapse );
+
+    push( @{ $attrs->{select} }, map { $_->[0] } @prefetch );
+    push( @{ $attrs->{as} },     map { $_->[1] } @prefetch );
+
+    push( @{ $attrs->{order_by} }, @$prefetch_ordering );
   }
 
   if (delete $attrs->{distinct}) {

Modified: DBIx-Class/0.08/trunk/t/prefetch/attrs_untouched.t
===================================================================
--- DBIx-Class/0.08/trunk/t/prefetch/attrs_untouched.t	2009-06-16 14:29:41 UTC (rev 6692)
+++ DBIx-Class/0.08/trunk/t/prefetch/attrs_untouched.t	2009-06-16 15:22:59 UTC (rev 6693)
@@ -8,17 +8,8 @@
 
 my $schema = DBICTest->init_schema();
 
-my $orig_debug = $schema->storage->debug;
+plan tests => 3;
 
-use IO::File;
-
-BEGIN {
-    eval "use DBD::SQLite";
-    plan $@
-        ? ( skip_all => 'needs DBD::SQLite for testing' )
-        : ( tests => 3 );
-}
-
 # bug in 0.07000 caused attr (join/prefetch) to be modifed by search
 # so we check the search & attr arrays are not modified
 my $search = { 'artist.name' => 'Caterwauler McCrae' };

Added: DBIx-Class/0.08/trunk/t/prefetch/double_prefetch.t
===================================================================
--- DBIx-Class/0.08/trunk/t/prefetch/double_prefetch.t	                        (rev 0)
+++ DBIx-Class/0.08/trunk/t/prefetch/double_prefetch.t	2009-06-16 15:22:59 UTC (rev 6693)
@@ -0,0 +1,35 @@
+use warnings;  
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBIC::SqlMakerTest;
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+plan tests => 1;
+
+# While this is a rather GIGO case, make sure it behaves as pre-103,
+# as it may result in hard-to-track bugs
+my $cds = $schema->resultset('Artist')
+            ->search_related ('cds')
+              ->search ({}, {
+                  prefetch => [ 'single_track', { single_track => 'cd' } ],
+                });
+
+is_same_sql(
+  ${$cds->as_query}->[0],
+  '(
+    SELECT
+      cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track,
+      single_track.trackid, single_track.cd, single_track.position, single_track.title, single_track.last_updated_on, single_track.last_updated_at,
+      single_track_2.trackid, single_track_2.cd, single_track_2.position, single_track_2.title, single_track_2.last_updated_on, single_track_2.last_updated_at,
+      cd.cdid, cd.artist, cd.title, cd.year, cd.genreid, cd.single_track
+    FROM artist me
+      LEFT JOIN cd cds ON cds.artist = me.artistid
+      LEFT JOIN track single_track ON single_track.trackid = cds.single_track
+      LEFT JOIN track single_track_2 ON single_track_2.trackid = cds.single_track
+      LEFT JOIN cd cd ON cd.cdid = single_track_2.cd
+  )',
+);




More information about the Bast-commits mailing list