[Bast-commits] r3454 - in branches/DBIx-Class-current: . lib/DBIx/Class t

matthewt at dev.catalyst.perl.org matthewt at dev.catalyst.perl.org
Fri Jun 1 00:18:24 GMT 2007


Author: matthewt
Date: 2007-06-01 00:18:23 +0100 (Fri, 01 Jun 2007)
New Revision: 3454

Modified:
   branches/DBIx-Class-current/Changes
   branches/DBIx-Class-current/lib/DBIx/Class/ResultSource.pm
   branches/DBIx-Class-current/t/76joins.t
   branches/DBIx-Class-current/t/90join_torture.t
Log:
LEFT join problem fixed

Modified: branches/DBIx-Class-current/Changes
===================================================================
--- branches/DBIx-Class-current/Changes	2007-05-31 23:18:11 UTC (rev 3453)
+++ branches/DBIx-Class-current/Changes	2007-05-31 23:18:23 UTC (rev 3454)
@@ -1,5 +1,6 @@
 Revision history for DBIx::Class
 
+        - fixup to ensure join always LEFT after first LEFT join depthwise
         - converted the vendor tests to use schema objects intead of schema
           classes, made cleaned more reliable with END blocks
         - versioning support via DBIx::Class::Schema::Versioned

Modified: branches/DBIx-Class-current/lib/DBIx/Class/ResultSource.pm
===================================================================
--- branches/DBIx-Class-current/lib/DBIx/Class/ResultSource.pm	2007-05-31 23:18:11 UTC (rev 3453)
+++ branches/DBIx-Class-current/lib/DBIx/Class/ResultSource.pm	2007-05-31 23:18:23 UTC (rev 3454)
@@ -713,16 +713,22 @@
 =cut
 
 sub resolve_join {
-  my ($self, $join, $alias, $seen) = @_;
+  my ($self, $join, $alias, $seen, $force_left) = @_;
   $seen ||= {};
+  $force_left ||= { force => 0 };
   if (ref $join eq 'ARRAY') {
     return map { $self->resolve_join($_, $alias, $seen) } @$join;
   } elsif (ref $join eq 'HASH') {
     return
       map {
         my $as = ($seen->{$_} ? $_.'_'.($seen->{$_}+1) : $_);
-        ($self->resolve_join($_, $alias, $seen),
-          $self->related_source($_)->resolve_join($join->{$_}, $as, $seen));
+        local $force_left->{force};
+        (
+          $self->resolve_join($_, $alias, $seen, $force_left),
+          $self->related_source($_)->resolve_join(
+            $join->{$_}, $as, $seen, $force_left
+          )
+        );
       } keys %$join;
   } elsif (ref $join) {
     $self->throw_exception("No idea how to resolve join reftype ".ref $join);
@@ -732,7 +738,13 @@
     my $as = ($count > 1 ? "${join}_${count}" : $join);
     my $rel_info = $self->relationship_info($join);
     $self->throw_exception("No such relationship ${join}") unless $rel_info;
-    my $type = $rel_info->{attrs}{join_type} || '';
+    my $type;
+    if ($force_left->{force}) {
+      $type = 'left';
+    } else {
+      $type = $rel_info->{attrs}{join_type} || '';
+      $force_left->{force} = 1 if lc($type) eq 'left';
+    }
     return [ { $as => $self->related_source($join)->from,
                -join_type => $type },
              $self->resolve_condition($rel_info->{cond}, $as, $alias) ];

Modified: branches/DBIx-Class-current/t/76joins.t
===================================================================
--- branches/DBIx-Class-current/t/76joins.t	2007-05-31 23:18:11 UTC (rev 3453)
+++ branches/DBIx-Class-current/t/76joins.t	2007-05-31 23:18:23 UTC (rev 3454)
@@ -336,21 +336,18 @@
 
 is($rs->next->name, 'Caterwauler McCrae', "Correct artist returned");
 
-TODO:  {
-    local $TODO = 'left join on prefetch to return valid rows';
-    my $cd = $schema->resultset('Artist')->first->create_related('cds',
-        {
-        title   => 'Unproduced Single',
-        year    => 2007
-    });
+my $cd = $schema->resultset('Artist')->first->create_related('cds',
+    {
+    title   => 'Unproduced Single',
+    year    => 2007
+});
 
-    my $left_join = $schema->resultset('CD')->search(
-        { 'me.cdid' => $cd->cdid },
-        { prefetch => { cd_to_producer => 'producer' } }
-    );
+my $left_join = $schema->resultset('CD')->search(
+    { 'me.cdid' => $cd->cdid },
+    { prefetch => { cd_to_producer => 'producer' } }
+);
 
-    cmp_ok($left_join, '==', 1, 'prefetch with no join record present');
-}
+cmp_ok($left_join, '==', 1, 'prefetch with no join record present');
 
 $queries = 0;
 $schema->storage->debugcb(sub { $queries++ });

Modified: branches/DBIx-Class-current/t/90join_torture.t
===================================================================
--- branches/DBIx-Class-current/t/90join_torture.t	2007-05-31 23:18:11 UTC (rev 3453)
+++ branches/DBIx-Class-current/t/90join_torture.t	2007-05-31 23:18:23 UTC (rev 3454)
@@ -23,8 +23,8 @@
 
 #this is wrong, should accept me.title really
 my $rs3 = $rs2->search_related('cds');
-cmp_ok(scalar($rs3->all), '==', 27, "All cds for artist returned");
-cmp_ok($rs3->count, '==', 27, "All cds for artist returned via count");
+cmp_ok(scalar($rs3->all), '==', 45, "All cds for artist returned");
+cmp_ok($rs3->count, '==', 45, "All cds for artist returned via count");
 
 my $rs4 = $schema->resultset("CD")->search({ 'artist.artistid' => '1' }, { join => ['tracks', 'artist'], prefetch => 'artist' });
 my @rs4_results = $rs4->all;




More information about the Bast-commits mailing list