DBIx::Class::Tree::AdjacencyList::Ordered - Glue DBIx::Class::Ordered and DBIx::Class::Tree::AdjacencyList together. |
DBIx::Class::Tree::AdjacencyList::Ordered - Glue DBIx::Class::Ordered and DBIx::Class::Tree::AdjacencyList together. (EXPERIMENTAL)
Create a table for your tree data.
CREATE TABLE items ( item_id INTEGER PRIMARY KEY AUTOINCREMENT, parent_id INTEGER NOT NULL DEFAULT 0, position INTEGER NOT NULL, name TEXT NOT NULL );
In your Schema or DB class add Tree::AdjacencyList::Ordered to the front of the component list.
__PACKAGE__->load_components(qw( Tree::AdjacencyList::Ordered ... ));
Specify the column that contains the parent ID and position of each row.
package My::Employee; __PACKAGE__->position_column('position'); __PACKAGE__->parent_column('parent_id');
This module provides a few extra methods beyond what the DBIx::Class::Ordered manpage and the DBIx::Class::Tree::AdjacencyList manpage already provide.
my $parent = $item->parent(); $item->parent( $parent_obj ); $item->parent( $parent_id ); my $children_rs = $item->children(); my @children = $item->children(); $parent->append_child( $child ); $parent->prepend_child( $child ); $this->attach_before( $that ); $this->attach_after( $that );
This module provides methods for working with adjacency lists and ordered rows. All of the methods that the DBIx::Class::Ordered manpage and the DBIx::Class::Tree::AdjacencyList manpage provide are available with this module.
__PACKAGE__->parent_column('parent_id');
Works the same as AdjacencyList's parent_column()
method, but it
declares the children()
has many relationship to be ordered by the
position column.
my $parent = $item->parent(); $item->parent( $parent_obj ); $item->parent( $parent_id );
This method overrides AdjacencyList's parent()
method but
modifies it so that the object is moved to the last position,
then the parent is changed, and then it is moved to the last
position of the new list, thus maintaining the intergrity of
the ordered lists.
my $children_rs = $item->children(); my @children = $item->children();
This method works just like it does in the DBIx::Class::Tree::AdjacencyList module except it orders the children by there position.
$parent->append_child( $child );
Sets the child to have the specified parent and moves the child to the last position.
$parent->prepend_child( $child );
Sets the child to have the specified parent and moves the child to the first position.
$this->attach_before( $that );
Attaches the object at the position just before the calling object's position.
$this->attach_after( $that );
Attaches the object at the position just after the calling object's position.
Aran Clary Deltac <bluefeet@cpan.org>
You may distribute this code under the same terms as Perl itself.
DBIx::Class::Tree::AdjacencyList::Ordered - Glue DBIx::Class::Ordered and DBIx::Class::Tree::AdjacencyList together. |