Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAttributeModel()
 {
     return $this->hasOne(Attribute::className(), ['id' => 'attribute_id']);
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAttributes()
 {
     return $this->hasMany(Attribute::className(), ['attribute_type_id' => 'id']);
 }