pll
pll

Reputation: 297

CakePHP join Unique constraint for a model

How would I enforce a model constraint for a table users, where not only does the username have to be unique for the users table, but also cannot exist in another table? Thanks!

Upvotes: 0

Views: 208

Answers (1)

deceze
deceze

Reputation: 521995

public $validate = array(
    'username' => array(
        'unique' => array(
            'rule' => 'veryUnique',
            ...
        )
    )
);

public function veryUnique($data) {
    return $this->isUnique($data) && $this->OtherModel->isUnique($data);
}

Upvotes: 2

Related Questions