does exists a “unique” validation rule (if does, how to implement it?) or must be implemented via callback?
Thanks.
does exists a unique validation rule (if does, how to implement it?) or must
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
)
As far as I know there is no universal “unique” (or “is_unique”) rule of Validation class.
That’s probably because of not regular nature of this kind of check.
However, if you would like do it nicely, you could create a ‘base model’ for all your models you use in your application (make them extend the base one).
Then, the uniqueness could be checked more or less like this:
In your validation rules you have to add this rule:
I have internal model rules stored in the method
rules(), as recommended.So this could be a live example:
Now every model extending the Model_Base_Model will be now able to check it’s uniqueness while creating.
Hope this helps! 🙂