I have an update form for user information. All data that has been filled out and is displayed in the form (as default value of field). The email address is both unique and required. If I load the form and save it without altering the email address, it tells me that email address already has already been taken. Is that a bug in the Yii or did I do something wrong?
Ok, I thought the unique validator would check whether this is about updating an existing record (doesn’t have to be unique) or inserting a new record.
That is not entirely true. You can if you load the record from the DB and just apply the new attributes. Now if your emailaddress didn’t change, the unique validator won’t fail.
In any case CUniqueValidators exclude the the actual record while checking for unicity.
That allows to update any fields safely, so if you don’t change the email, you will not have error, if you change the email to another already used email, you will have the error as expected.