/** * Load edit models * @param array $primaryKey Primary key * @return mixed * @throws InvalidParamException */ protected function loadEditModels(array $primaryKey = []) { $models = []; if (!empty($primaryKey)) { $models['main'] = Attribute::findOne($primaryKey); if ($models['main'] === null) { throw new InvalidParamException('Main model could not be found.'); } else { $models['main']->scenario = 'update'; } } else { $models['main'] = new Attribute(['scenario' => 'insert']); } if ($this->modelExist('i18n')) { $models['i18n'] = new $this->crudModelsClass['i18n'](); $models['i18n']->scenario = 'beforeInsert'; if (!empty($primaryKey) && !$models['main']->isNewRecord) { $tmp = AttributeI18n::findOne(['attribute_id' => $models['main']->id, 'i18n_id' => Yii::$app->language]); if ($tmp !== null) { $models['i18n'] = $tmp; $models['i18n']->scenario = 'update'; unset($tmp); } } } return $models; }
/** * @return \yii\db\ActiveQuery */ public function getAttributeI18ns() { return $this->hasMany(AttributeI18n::className(), ['attribute_id' => 'id']); }