Revision history for DBIx::Class::Tree
0.01000
+ - Removed the _grouping_clause override method.
+ - Created a TODO document.
+ - attach_child() attach_sibling() now accept more than
+ one object to attach.
- Added tests for Ordered.
- Renamed Positional as Ordered.
- Added tests for AdjacencyList.
--- /dev/null
+
+ - Support DAGs.
+ - Add is_leaf, is_parent, is_branch, and is_root.
+ - Tree::Visitor
+ - Come up with a better name for attach_before and attach_after.
+ - Support multiple columns for ordering.
+ - Declare both the parent column and the position column in one call.
+
In this model each row in a table has a prent ID column that references the
primary key of another row in the same table. Because of this the primary
key must only be one column and is usually some sort of integer. The row
-with a parent ID of 0 is the root row and is usually the parent of all
-other rows.
+with a parent ID of 0 is the root node and is usually the parent of all
+other rows. Although, there is no limitation in this module that would
+stop you from having multiple root nodes.
=head1 METHODS
$employee->parent( $parent_id );
Retrieves the object's parent object, or changes the object's
-parent to the specified parent or parent ID.
+parent to the specified parent or parent ID. If you would like
+to make the object the root node, just set the parent to 0.
+
+If you are setting the parent then 0 will be returned if the
+specified parent is already the object's parent and 1 on
+success.
=cut
=head2 attach_child
$parent->attach_child( $child );
+ $parent->attach_child( $child, $child, ... );
-Sets the child to the new parent.
+Sets the child, or children, to the new parent. Returns 1
+on success and returns 0 if the parent object already has
+the child.
=cut
sub attach_child {
- my( $self, $child ) = @_;
- return $child->parent( $self );
+ my $self = shift;
+ my $return = 1;
+ foreach my $child (@_) {
+ $child->parent( $self );
+ }
+ return $return;
}
=head2 siblings
=head2 attach_sibling
- $this->attach_sibling( $that );
+ $obj->attach_sibling( $sibling );
+ $obj->attach_sibling( $sibling, $sibling, ... );
-Sets the passed in object to have the same parent
-as the calling object.
+Sets the passed in object(s) to have the same parent
+as the calling object. Returns 1 on success and
+0 if the sibling already has the same parent.
=cut
sub attach_sibling {
- my( $self, $node ) = @_;
- return $node->parent( $self->parent() );
+ my $self = shift;
+ my $return = 1;
+ foreach my $node (@_) {
+ $return = 0 if (!$node->parent( $self->parent() ));
+ }
+ return $return;
}
1;
use Carp qw( croak );
__PACKAGE__->load_components(qw(
- Tree::AdjacencyList
Ordered
+ Tree::AdjacencyList
));
=head1 NAME
);
In your Schema or DB class add Tree::AdjacencyList::Ordered
-to the top of the component list.
+to the front of the component list.
__PACKAGE__->load_components(qw( Tree::AdjacencyList::Ordered ... ));
sub parent_column {
my $class = shift;
+ my $position_col = $class->position_column() || croak('You must call position_column() before calling parent_column()');
if (@_) {
- my $parent_col = shift;
- my $primary_col = ($class->primary_columns())[0];
- my $position_col = $class->position_column() || croak('You must call position_column() before calling parent_column()');
- $class->belongs_to( '_parent' => $class => { "foreign.$primary_col" => "self.$parent_col" } );
- $class->has_many( 'children' => $class => { "foreign.$parent_col" => "self.$primary_col" }, { order_by=>$position_col } );
- $class->_parent_column( $parent_col );
+ $class->grouping_column( @_ );
+ $class->next::method( @_ );
+ $class->relationship_info('children')->{attrs}->{order_by} = $position_col;
return 1;
}
- return $class->_parent_column();
+ return $class->grouping_column;
}
=head2 parent
$sibling->move_to( $self->get_column($self->position_column()) + 1 );
}
-=head1 PRIVATE METHODS
-
-These methods are used internally. You should never have the
-need to use them.
-
-=head2 grouping_column
-
-Postional's grouping_column method does not, and should not, be
-defined when using this module. This method just throws out an
-error if you try to use it.
-
-=cut
-
-sub grouping_column {
- croak('Use parent_column() instead of grouping_column()');
-}
+1;
+__END__
-=head2 _grouping_clause
+=head1 INHERITED METHODS
-This method is provided as an override of the method in
-L<DBIx::Class::Ordered>. This method is what provides the
-glue between AdjacencyList and Ordered.
+This module inherits all methods from L<DBIx::Class::Ordered>.
-=cut
+ siblings
+ first_sibling
+ last_sibling
+ previous_sibling
+ next_sibling
+ move_previous
+ move_next
+ move_first
+ move_last
+ move_to
+ insert
+ delete
-sub _grouping_clause {
- my( $self ) = @_;
- my $col = $self->_parent_column();
- return (
- $col => $self->get_column( $col )
- );
-}
+And L<DBIx::Class::Tree::AdjacencyList>.
-1;
-__END__
+ attach_child
+ attach_sibling
=head1 AUTHOR