optimized is_leaf to not trigger another query if the children releationship is prefe...
Alexander Hartmaier [Thu, 20 Jan 2011 13:22:55 +0000 (14:22 +0100)]
Changes
lib/DBIx/Class/Tree/AdjacencyList.pm

diff --git a/Changes b/Changes
index ef75b2b..8cdbe24 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,9 @@
 
 Revision history for DBIx::Class::Tree
 
+    - Optimized is_leaf to not trigger another query if the children
+      releationship is prefetched
+
 0.03002 2010-09-23
     - Added various docs
     - Added ordered ancesors (nebulous)
index e668a38..e14875f 100644 (file)
@@ -309,10 +309,7 @@ Returns 1 if the object has no children, and 0 otherwise.
 sub is_leaf {
     my( $self ) = @_;
 
-    my $has_child = $self->result_source->resultset->search(
-        { $self->_parent_column => $self->id() },
-        { limit => 1 }
-    )->count();
+    my $has_child = $self->children_rs->count();
 
     return $has_child ? 0 : 1;
 }