public function beforeSave($insert) { if (parent::beforeSave($insert)) { $orders = $this->getDirtyAttributes(['orders']); if (!empty($orders)) { $this->reOrder($orders); } $parent = $this->getDirtyAttributes(['parent']); if (!empty($parent)) { $ancestor = $this->find()->where(['id' => $parent])->one(); $this->ancestor = $ancestor->ancestor; } return true; } return false; }