You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
831 B

<?php
/**
* @link https://github.com/paulzi/yii2-nested-sets
* @copyright Copyright (c) 2015 PaulZi <pavel.zimakoff@gmail.com>
* @license MIT (https://github.com/paulzi/yii2-nested-sets/blob/master/LICENSE)
*/
namespace paulzi\nestedsets;
/**
* @author PaulZi <pavel.zimakoff@gmail.com>
*/
trait NestedSetsQueryTrait
{
/**
* @return \yii\db\ActiveQuery
*/
public function roots()
{
/** @var \yii\db\ActiveQuery $this */
$class = $this->modelClass;
if (isset($class::$nestedSetsLeftAttribute)) {
return $this->andWhere([$class::$nestedSetsLeftAttribute => 1]);
} else {
/** @var \yii\db\ActiveRecord|NestedSetsBehavior $model */
$model = new $class;
return $this->andWhere([$model->leftAttribute => 1]);
}
}
}