Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon Model validate uniqueness by two fields

I want to validate the uniqueness of a model by two fields but I can't find an example.

Here is an example of a single field:

public function validation()
{
    $this->validate(new Uniqueness(array(
        'field' => 'email'
    )));
}

What do you mean "by two fields" - do you want to make a single value a unique value when checked against two database columns?



4.0k
Accepted
answer
edited Dec '14

try this:

public function validation()
{
    $this->validate(new Uniqueness(array(
        'field' => array('email', 'name')
    )));
}


45.8k

Vladimir thanks, that seems like what I'm looking for.



222

try this:

```php public function validation() { $this->validate(new Uniqueness(array( 'field' => array('email', 'name') ))); } ```

And how can i add this, to a form validator? While i set the 'field', phalcon still using the 'attribute'.