'onAfterFind', ActiveRecord::EVENT_BEFORE_INSERT => 'onBeforeSave', ActiveRecord::EVENT_BEFORE_UPDATE => 'onBeforeSave', ]; } public function onAfterFind(Event $event): void { $model = $event->sender; $meta = Json::decode($model->getAttribute($this->jsonAttribute)); $model->{$this->attribute} = new Meta( ArrayHelper::getValue($meta, 'title'), ArrayHelper::getValue($meta, 'description'), ArrayHelper::getValue($meta, 'keywords') ); } public function onBeforeSave(Event $event): void { $model = $event->sender; $model->setAttribute('meta_json', Json::encode([ 'title' => $model->{$this->attribute}->title, 'description' => $model->{$this->attribute}->description, 'keywords' => $model->{$this->attribute}->keywords, ])); } }