Column used to store the item’s depth inside the tree. Data type must be int.
Returns: | Model parent item, if it exists, null otherwise. |
---|
Set a new parent for the item.
If the item is twinnable and if it exists in several contexts, all contexts will be moved synchronously.
Parameters: |
|
---|---|
Throws: | Exception when:
|
Returns: | All direct children of item. |
---|
Children can be filter and / or sort by parameters.
<?php
$options = \Arr::merge($options, array(
'where' => $where,
'order_by' => $order_by,
));
Parameters: |
|
---|---|
Returns: | All children of item and their descendants. |
Returns: | First ascendant of item in tree or null if item has no parent. |
---|
This behaviour extends Model->find().
Add option to where array passed to method : you can use parent key as alias for search in Orm_Behaviour_Tree::$parent_relation relation.
<?php
class Model_Page extends \Nos\Orm\Model
{
protected static $_behaviours = array(
'Nos\Orm_Behaviour_Tree' => array(
'events' => array('before_query', 'after_delete'),
'parent_relation' => 'parent',
'children_relation' => 'children',
'level_property' => 'page_level',
),
);
protected static $_has_many = array(
'children' => array(
'key_from' => 'page_id',
'model_to' => 'Nos\Model_Page',
'key_to' => 'page_parent_id',
'cascade_save' => false,
'cascade_delete' => false,
),
);
protected static $_belongs_to = array(
'parent' => array(
'key_from' => 'page_parent_id',
'model_to' => 'Nos\Model_Page',
'key_to' => 'page_id',
'cascade_save' => false,
'cascade_delete' => false,
),
);
}