optimized is_leaf to not trigger another query if the children releationship is prefe...
[dbsrgits/DBIx-Class-Tree.git] / lib / DBIx / Class / Tree / AdjacencyList.pm
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;
 }