*/ class NestedSetsQueryBehavior extends Behavior { /** * Gets the root nodes. * @return \yii\db\ActiveQuery the owner */ public function roots() { $this->owner->andWhere([(new $this->owner->modelClass())->leftAttribute => 1]); return $this->owner; } /** * Gets the leaf nodes. * @return \yii\db\ActiveQuery the owner */ public function leaf() { $model = new $this->owner->modelClass(); $db = $model->getDb(); $this->owner->andWhere(new Expression( $db->quoteColumnName($model->rightAttribute) . ' - ' . $db->quoteColumnName($model->leftAttribute) . ' = 1' )); return $this->owner; } }