[Bast-commits] r3660 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class

matthewt at dev.catalyst.perl.org matthewt at dev.catalyst.perl.org
Wed Aug 8 11:35:27 GMT 2007


Author: matthewt
Date: 2007-08-08 11:35:26 +0100 (Wed, 08 Aug 2007)
New Revision: 3660

Modified:
   DBIx-Class/0.08/trunk/Changes
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
Log:
rejig resultset construction for related_resultset

Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes	2007-08-07 21:56:15 UTC (rev 3659)
+++ DBIx-Class/0.08/trunk/Changes	2007-08-08 10:35:26 UTC (rev 3660)
@@ -1,4 +1,7 @@
 Revision history for DBIx::Class
+
+        - provide alias for related_resultset via local() so it's set
+          correctly at resultset construction time (fixes RestrictWithObject)
         - fixes bind params in debug statements
           (original test from abraxxa)
         - fixed storage->connected fork bug

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2007-08-07 21:56:15 UTC (rev 3659)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2007-08-08 10:35:26 UTC (rev 3660)
@@ -971,7 +971,7 @@
   # offset, order by and page are not needed to count. record_filter is cdbi
   delete $attrs->{$_} for qw/rows offset order_by page pager record_filter/;
 
-  my $tmp_rs = (ref $self)->new($self->_source_handle, $attrs);
+  my $tmp_rs = (ref $self)->new($self->result_source, $attrs);
   my ($count) = $tmp_rs->cursor->next;
   return $count;
 }
@@ -1409,7 +1409,7 @@
 
 sub page {
   my ($self, $page) = @_;
-  return (ref $self)->new($self->_source_handle, { %{$self->{attrs}}, page => $page });
+  return (ref $self)->new($self->result_source, { %{$self->{attrs}}, page => $page });
 }
 
 =head2 new_result
@@ -1737,7 +1737,7 @@
     my $rel_obj = $self->result_source->relationship_info($rel);
 
     $self->throw_exception(
-      "search_related: result source '" . $self->_source_handle->source_moniker .
+      "search_related: result source '" . $self->result_source->source_name .
         "' has no such relationship $rel")
       unless $rel_obj;
     
@@ -1748,7 +1748,7 @@
 
     #XXX - temp fix for result_class bug. There likely is a more elegant fix -groditi
     my %attrs = %{$self->{attrs}||{}};
-    delete $attrs{result_class};
+    delete @attrs{qw(result_class alias)};
 
     my $new_cache;
 
@@ -1759,21 +1759,32 @@
       }
     }
 
-    my $new = $self->_source_handle
-                   ->schema
-                   ->resultset($rel_obj->{class})
-                   ->search_rs(
-                       undef, {
-                         %attrs,
-                         join => undef,
-                         prefetch => undef,
-                         select => undef,
-                         as => undef,
-                         alias => $alias,
-                         where => $self->{cond},
-                         seen_join => $seen,
-                         from => $from,
-                     });
+    my $rel_source = $self->result_source->related_source($rel);
+
+    my $new = do {
+
+      # The reason we do this now instead of passing the alias to the
+      # search_rs below is that if you wrap/overload resultset on the
+      # source you need to know what alias it's -going- to have for things
+      # to work sanely (e.g. RestrictWithObject wants to be able to add
+      # extra query restrictions, and these may need to be $alias.)
+
+      my $attrs = $rel_source->resultset_attributes;
+      local $attrs->{alias} = $alias;
+
+      $rel_source->resultset
+                 ->search_rs(
+                     undef, {
+                       %attrs,
+                       join => undef,
+                       prefetch => undef,
+                       select => undef,
+                       as => undef,
+                       where => $self->{cond},
+                       seen_join => $seen,
+                       from => $from,
+                   });
+    };
     $new->set_cache($new_cache) if $new_cache;
     $new;
   };




More information about the Bast-commits mailing list