diff --git a/NestedSetQuery.php b/NestedSetQuery.php new file mode 100644 index 0000000..52befba --- /dev/null +++ b/NestedSetQuery.php @@ -0,0 +1,40 @@ + + */ +class NestedSetQuery extends Behavior +{ + /** + * @var ActiveQuery the owner of this behavior. + */ + public $owner; + public $hasManyRoots = false; + public $rootAttribute = 'root'; + public $leftAttribute = 'lft'; + public $rightAttribute = 'rgt'; + public $levelAttribute = 'level'; + + /** + * Named scope. Gets root node(s). + * @param ActiveQuery $query. + * @return ActiveRecord the owner. + */ + public function roots($query) + { + /** @var $modelClass ActiveRecord */ + $modelClass=$this->owner->modelClass; + $query->andWhere($modelClass::getDb()->quoteColumnName($this->leftAttribute) . '=1'); + } +}