validation - cakephp 3 add unique constraint -
i'm sorry ask such "easy" question. tried following add unique validation rule model:
$validator ->requirepresence('pseudonym', 'create',['rule' => 'isunique']) ->notempty('pseudonym');
now don't error. if add database-constraint database-error:
integrity constraint violation: 1062 duplicate entry 'stella' key 'pseudonym'
if add:
$validator ->add('pseudonym','unique',['rule' => 'validateunique']);
i a
method validateunique not found
exception.
so how work cakephp 3?
cakephp has rule class allows define unique fields http://book.cakephp.org/3.0/en/orm/validation.html#creating-unique-field-rules
use cake\orm\rule\isunique; // single field. $rules->add($rules->isunique(['email'])); // list of fields $rules->add($rules->isunique(['username', 'account_id']));
Comments
Post a Comment