Answer the question
In order to leave comments, you need to log in
How to check for uniqueness of 2 fields in Yii2?
hello. there are 2 fields in the database: 'parent_id' and 'email'
how to check both fields?
those. there can be entries
email = [email protected] and parent_id = 1
email = [email protected] and parent_id = 2
but both values cannot be repeated at the same time
If unique is specified in the model, then only email is unique, then parent_id does not play a role
public function rules()
{
return [
[['parent_id'], 'integer'],
[['email'], 'email'],
[['email'], 'unique'],
];
}
['parent_id AND email'], 'unique']
, but this does not work)
Decision:[['parent_id', 'email'], 'unique', 'targetAttribute' => ['parent_id', 'email']],
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question