/** * Validation rules * @return array */ public function rules() { $rules = $this->_model->rules(); $rules[] = ['tags', 'exist', 'targetClass' => Tag::className(), 'targetAttribute' => 'id', 'allowArray' => true]; $rules['keyExists'] = ['key', 'unique', 'targetClass' => Post::className(), 'targetAttribute' => 'key', 'when' => function ($model) { return $model->key != $model->item->key; }]; return $rules; }
public function getTags() { return $this->hasMany(Tag::className(), ['id' => 'tag_id'])->via('tagRelation'); }