mirror of
https://github.com/Oreolek/yii2-nested-sets.git
synced 2024-06-17 07:10:46 +03:00
Added NestedSetsBehavior::leaves feature
This commit is contained in:
parent
c5cde0e6da
commit
42d25ce72a
|
@ -247,6 +247,24 @@ class NestedSetsBehavior extends Behavior
|
|||
return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the leaves of the node.
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function leaves()
|
||||
{
|
||||
$condition = [
|
||||
'and',
|
||||
['>', $this->leftAttribute, $this->owner->getAttribute($this->leftAttribute)],
|
||||
['<', $this->rightAttribute, $this->owner->getAttribute($this->rightAttribute)],
|
||||
[$this->rightAttribute => new Expression($this->owner->getDb()->quoteColumnName($this->leftAttribute) . '+ 1')],
|
||||
];
|
||||
|
||||
$this->applyTreeAttributeCondition($condition);
|
||||
|
||||
return $this->owner->find()->andWhere($condition)->addOrderBy([$this->leftAttribute => SORT_ASC]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the previous sibling of the node.
|
||||
* @return \yii\db\ActiveQuery
|
||||
|
|
Loading…
Reference in a new issue