Hi,
I have a problem with the unique validator rule.
For example I have a user who wants to update its email address, but he/she does not want to update its username. These two fields are uniques. So my problem is, when the user change its email address the uniqe validator works fine, but while user does not update its username field, the unique validator rule will check its username too in the database and will return with error. But I want to avoid that the unique validator role check the updating model’s field.
So when I updating the users attributes the unique validator rule will get errors, casuse it checks the current updating model’s field too…
/**
* @inheritdoc
*/
public function rules()
{
return [
['username', 'filter', 'filter' => 'trim'],
['username', 'required'],
['username', 'unique', 'targetClass' => '\app\models\User', 'message' => 'This username has already been taken.'],
['username', 'string', 'min' => 2, 'max' => 255],
['email', 'filter', 'filter' => 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'string', 'max' => 255],
['email', 'unique', 'targetClass' => '\app\models\User', 'message' => 'This email address has already been taken.'],
['password', 'string', 'min' => 6],
['passwordRepeat', 'compare', 'compareAttribute' => 'password', 'message' => 'The password does not match.'],
];
}