/** * 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 getPost() { return $this->hasOne(Post::className(), ['id' => 'post_id']); }