Open vercotux opened 7 years ago
the unique validator takes the case into account when the model is updated, so the record that is currently updated does not count as a duplicate record on update. This is also verified by a unit test:
Can you provide some code to reproduce the problem? The links to stackoverflow does not contain useful info as far as I see.
according to the answer the problem was due to a typo.
https://stackoverflow.com/questions/44469776/yii2-on-update-action-for-unique-attribute
unable to reproduce.
unable to reproduce. The solution adds a problem that updating the field does not check for uniqueness!?
https://stackoverflow.com/questions/35695940/ajax-validation-unique-on-update
The problem here is a typo in targetClass, SmCategory
vs. Smcategory
.
These seem to be generally confused about what they want.
Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:
Thanks!
This is an automated comment, triggered by adding the label status:need more info
.
I was able to reproduce the issue. This seems to happen in a very specific situation where you have multiple unrelated unique attributes in the same model and at least 2 are marked as dirty (but identical to their original/old values!). And I think one of them has to be the primary key.
For example:
$model = SomeModel::find()->one();
$model->markAttributeDirty('id');
$model->markAttributeDirty('another_unique_column');
$model->validate(); // will report 'another_unique_column' as taken.
This is a feature request to add a boolean
excludeSelf
(orfilterSelf
) option to UniqueValidator.Such an option is particularly useful when updating an existing record which already has the unique attribute set. Right now UniqueValidator will add an error if we update the unique value to the same value, which is not right imo. Even though the unique attribute is marked as dirty, if it is identical to the original one, it should pass validation or even skip the check entirely.
It seems to be a rather common issue: