gpt4 book ai didi

yii2 - 如何在ActiveRecord(Yii2)中为多个字段设置唯一性?

转载 作者:行者123 更新时间:2023-12-03 13:56:17 27 4
gpt4 key购买 nike

如何在ActiveRecord(Yii2)中为多个字段设置唯一性?
我已经尝试过手动编写

['a1', 'unique', 'targetAttribute' => ['a1', 'a2']]

但这是行不通的。

最佳答案

从文档:

// a1 needs to be unique
['a1', 'unique']
// a1 needs to be unique, but column a2 will be used to check the uniqueness of the a1 value
['a1', 'unique', 'targetAttribute' => 'a2']
// a1 and a2 need to be unique together, and they both will receive error message
[['a1', 'a2'], 'unique', 'targetAttribute' => ['a1', 'a2']]
// a1 and a2 need to be unique together, only a1 will receive error message
['a1', 'unique', 'targetAttribute' => ['a1', 'a2']]
// a1 needs to be unique by checking the uniqueness of both a2 and a3 (using a1 value)
['a1', 'unique', 'targetAttribute' => ['a2', 'a1' => 'a3']]

关于yii2 - 如何在ActiveRecord(Yii2)中为多个字段设置唯一性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27565465/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com