Nos\
Orm_Behaviour_Tree
¶Nos\Orm\Model
behaves like a Tree.Nos\Orm_Behaviour_Tree::$
level_property
¶Column used to store the item’s depth inside the tree. Data type must be int
.
Nos\Orm_Behaviour_Tree::
get_parent
()¶Returns: | Model parent item, if it exists, null otherwise. |
---|
Nos\Orm_Behaviour_Tree::
set_parent
($new_parent)¶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: |
|
Nos\Orm_Behaviour_Tree::
find_children
($where = array(), $order_by = array(), $options = array())¶Returns: | All direct children of item. |
---|
Children can be filter and / or sort by parameters.
$options
parameter are passed to ->find()
like that:<?php
$options = \Arr::merge($options, array(
'where' => $where,
'order_by' => $order_by,
));
Nos\Orm_Behaviour_Tree::
find_children_recursive
($include_self = true)¶Parameters: |
|
---|---|
Returns: | All children of item and their descendants. |
Nos\Orm_Behaviour_Tree::
find_root
()¶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,
),
);
}