This extension, takes a combination of Model attributes and verifies uniqueness of the combination in the database table.
Credit: I took the original code posted by me23 at this Forum topic and packaged it with minor modification to raise an error referencing the attribute combination and not a single attribute. Other than that, the credit it to the community.
protected/extensionsSee the following code example:
public function rules() { return array( .... array('attribute1+attribute2+attribute3', 'application.extensions.uniqueMultiColumnValidator'), ....
Total 13 comments
When you use this extension with PostgreSQL and you try to validate integer type fields you get error:
Simple workaround for this: set caseSensitive to true:
Because of looping error message. I'm not sure if it is a good way, but change the code :
to
will solve the problem. Any better approach?
Very useful extension, but why I get two error message on validation fail?
Or, you can pass the parameter when configuring the rule.
Make it work with name and date combination
The extension does not work when a field is a date. This is due to the conversion to lowercase which is performed when the caseSensitive property is left to false, which is the default. My brutal fix was to change the default from false to true in row 8 of the class uniqueMultiColumnValidator.php
Hope someone will provide a better fix (testing for field type before the conv. to lowercase, etc...)
Thank you!
Hi,
I have Member table which contains membershipNo, name and date, I want to implement a validation that combination of name and date must be unique, but the validation always through....... If I changed to membershipNo and name it works fine.
Any hints?
Hi, what should i do to make it check the values after the beforeSave() makes changes ?
Thank you, i didn't have to reinvert the wheel. :) Works like a charm.
@Inkvizitor: What' with NULL values?
Firstly great job, congrat to me23 afiouni and community. @Inkvizitor: What's the behavior of null values ?
One problem: extension doesn't work with NULL values correctly.
Thanks for share!
Leave a comment
Please login to leave your comment.