__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.
$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
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;
}