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 d913113..e14875f 100644 (file)
@@ -66,11 +66,10 @@ stop you from having multiple root nodes.
   __PACKAGE__->parent_column('parent_id');
 
 Declares the name of the column that contains the self-referential
-ID which defines the parent row.  Defaults to "parent_id".  This
-will create a has_many (children) and belongs_to (parent)
-relationship.
+ID which defines the parent row.  This will create a has_many (children) 
+and belongs_to (parent) relationship.
 
-This method also setups an additional has_many relationship called
+This method also sets up an additional has_many relationship called
 parents which is useful when you want to treat an adjacency list
 as a DAG.
 
@@ -114,7 +113,7 @@ And you execute:
 
   $b->parent( $d );
 
-Since D is a descendant of B then all of B's siblings get their parent
+Since D is a descendant of B then all of D's siblings get their parent
 changed to A.  Then B's parent is set to D.
 
   A
@@ -310,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;
 }