Uniqueness with combination of a set of fields

Hi guys,

Could anyone explain to me how I might validate the uniqueness of a combination of a set of fields? The documentation at http://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Validator_Uniqueness.html mentions the possibility to do this, but it doesn't offer an example.

Would it be as simple as doing something like this (?):

$this->validate(new Uniqueness(array(
    'field' => 'id, email'
)));
if ($this->validationHasFailed() == true) {
    return false;
}

I'll be trying that one out sometime tonight, but if anyone reads this in the mean time and knows the answer, I'd be grateful if you'd share your knowledge with me. Thanks!

My guess is you should pass multiple fields as an array, not a comma separated list. You're probably trying to avoid this - but you can of course put in separate validation rules for each field.



85.4k

It must work this way:

$this->validate(new Uniqueness(array(
    'field' => array('id', 'email')
)));
if ($this->validationHasFailed() == true) {
    return false;
}