'afterSave', ActiveRecord::EVENT_AFTER_UPDATE => 'afterSave', ActiveRecord::EVENT_AFTER_DELETE => 'afterDelete' ]; } public function afterSave() { if (\Yii::$app->request->isConsoleRequest ) { return; } $model = $this->getMetaModel(); if ($model->load(Yii::$app->request->post())) { $model->save(); } } public function afterDelete() { $this->getMetaModel()->delete(); } public function getMetaModel() { $model = $this->owner->meta; if ($model == null) { $model = new Meta([ 'entity' => $this->getEntity(), 'entity_id' => $this->getEntityId() ]); } return $model; } public function getMeta() { return $this->owner->hasOne(Meta::className(), [ 'entity_id' => $this->owner->primaryKey()[0] ])->where([ "entity" => $this->getEntity() ]); } }