[Bast-commits] r4627 - DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree

rafl at dev.catalyst.perl.org rafl at dev.catalyst.perl.org
Fri Jul 25 01:43:35 BST 2008


Author: rafl
Date: 2008-07-25 01:43:35 +0100 (Fri, 25 Jul 2008)
New Revision: 4627

Modified:
   DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree/NestedSet.pm
Log:
Narrow down children search to childs of the row we're searching on.

This can't be done in the join condition because that'd infer the
condition on create, which is obviously wrong.

Modified: DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree/NestedSet.pm
===================================================================
--- DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree/NestedSet.pm	2008-07-25 00:43:29 UTC (rev 4626)
+++ DBIx-Class-Tree-NestedSet/lib/DBIx/Class/Tree/NestedSet.pm	2008-07-25 00:43:35 UTC (rev 4627)
@@ -105,4 +105,22 @@
     return $self->next::method($rel => $col_data);
 }
 
+sub search_related {
+    my ($self, $rel, $cond, @rest) = @_;
+
+    if ($rel eq 'children') {
+        my $pk = ($self->result_source->primary_columns)[0];
+
+        $cond ||= {};
+        $cond->{"parent.$pk"} = $self->$pk,
+    }
+
+    return $self->next::method($rel, $cond, @rest);
+}
+
+{
+    no warnings 'once';
+    *search_related_rs = \&search_related;
+}
+
 1;




More information about the Bast-commits mailing list