如何为多个属性的组合指定模型中的唯一规则?
我想要一个规则,不允许插入具有相同FIELD100
,FIELD3
return [
[['FEETYPE_F_V_R_','FIELD32','IS_CUSTOMER_EXPENSE','IS_BANK_EXPENSE','IS_BANK_EXPENSE','FIELD100'], 'required'],
[['ID', 'ACTIVE', 'APPROVED', 'REWORKED', 'IS_CUSTOMER_EXPENSE', 'IS_BANK_EXPENSE', 'IS_BANK_EXPENSE'], 'integer'],
[['AMOUNT'], 'number'],
[['REWORKEDON'], 'safe'],
[['FIELD3', 'FIELD32'], 'string', 'max' => 10],
[['FEETYPE_F_V_R_', 'FIELD24'], 'string', 'max' => 2],
[['FIELD100', 'CREATEDBY', 'APPROVEDBY', 'REWORKEDBY'], 'string', 'max' => 50],
[['CREATEDDATE', 'APPROVEDDATE'], 'string', 'max' => 7],
[['MEMOCODE'], 'string', 'max' => 20],
[['ID'], 'unique'],
];
答案 0 :(得分:0)
您可以在模型中使用CompareValidator。
public function rules()
{
return [
[
'FIELD100',
'compare',
'compareAttribute' => 'FIELD3',
'operator' => '!=',
'message' => 'Both values can not be the same'
]
];
}
有关更多信息,请参见docs