/** * @inheritdoc */ public function behaviors() { return [['class' => SortableBehavior::className(), 'query' => function ($model) { /** @var ItemWindow $model */ $tableName = $model->tableName(); return $model->find()->andWhere(["{$tableName}.[[parent_id]]" => $model->parent_id]); }, 'joinMode' => false]]; }
/** * @param ActiveRecord $owner */ public function attach($owner) { parent::attach($owner); if ($this->sortable !== false) { $this->behavior = Yii::createObject(array_merge(['class' => SortableBehavior::className(), 'query' => [$this->parentAttribute]], $this->sortable)); $owner->attachBehavior('adjacency-list-sortable', $this->behavior); } }
/** * @param ActiveRecord $owner * @throws Exception */ public function attach($owner) { parent::attach($owner); if ($this->itemAttribute === null) { $primaryKey = $owner->primaryKey(); if (!isset($primaryKey[0])) { throw new Exception('"' . $owner->className() . '" must have a primary key.'); } $this->itemAttribute = $primaryKey[0]; $this->primaryKeyMode = true; } if ($this->sortable !== false) { $this->behavior = Yii::createObject(array_merge(['class' => SortableBehavior::className(), 'query' => function () { return $this->getSortableQuery(); }], $this->sortable)); $owner->attachBehavior('materialized-path-sortable', $this->behavior); } }
/** * @inheritdoc */ public function behaviors() { return [['class' => SortableBehavior::className(), 'query' => ['parent_id']]]; }