yii: how to make a unique rule for two attributes

后端 未结 8 530
一生所求
一生所求 2020-12-29 02:26

I have a table like this: (id, name, version, text). (name, version) is unique key, how can i make a rule to validate this.

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 03:04

    In Yii2:

    public function rules() {
        return [
            [['name'], 'unique', 'targetAttribute' => ['name', 'version']],
        ];
    }
    

提交回复
热议问题