---
name: "DBIx::Class::Tree::AdjacencyList::Ordered"
section: "3pm"
platform: "linux"
package: "libdbix-class-tree-perl"
version: "0.03003-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/DBIx::Class::Tree::AdjacencyList::Ordered"
---

# DBIx::Class::Tree::AdjacencyList::Ordered(3pm)

Glue DBIx::Class::Ordered and DBIx::Class::Tree::AdjacencyList together.

## NAME

DBIx::Class::Tree::AdjacencyList::Ordered - Glue DBIx::Class::Ordered and DBIx::Class::Tree::AdjacencyList together.

## SYNOPSIS

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  DBIx::Class::Ordered and DBIx::Class::Tree::AdjacencyList  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 );
```

## DESCRIPTION

This module provides methods for working with adjacency lists and ordered  rows.  All of the methods that DBIx::Class::Ordered and  DBIx::Class::Tree::AdjacencyList provide are available with this module.

## METHODS

### parent\_column

```
  __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.

### parent

```
  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.

### children

```
  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.

### append\_child

```
  $parent->append_child( $child );
```

Sets the child to have the specified parent and moves the  child to the last position.

### prepend\_child

```
  $parent->prepend_child( $child );
```

Sets the child to have the specified parent and moves the  child to the first position.

### attach\_before

```
  $this->attach_before( $that );
```

Attaches the object at the position just before the  calling object's position.

### attach\_after

```
  $this->attach_after( $that );
```

Attaches the object at the position just after the  calling object's position.

## INHERITED METHODS

### DBIx::Class::Ordered

- •

  siblings

- •

  first\_sibling

- •

  last\_sibling

- •

  previous\_sibling

- •

  next\_sibling

- •

  move\_previous

- •

  move\_next

- •

  move\_first

- •

  move\_last

- •

  move\_to

- •

  insert

- •

  delete

### DBIx::Class::Tree::AdjacencyList

- •

  parent\_column

- •

  parent

- •

  attach\_child

- •

  siblings

- •

  attach\_sibling

### DBIx::Class

- •

  mk\_classdata

- •

  component\_base\_class

### DBIx::Class::Componentised

- •

  inject\_base

- •

  load\_components

- •

  load\_own\_components

### Class::Data::Accessor

- •

  mk\_classaccessor

## AUTHOR

Aran Clary Deltac \<bluefeet@cpan.org\>

## LICENSE

You may distribute this code under the same terms as Perl itself.
