-
Notifications
You must be signed in to change notification settings - Fork 141
isUnique validation
ichikaway edited this page Feb 7, 2011
·
4 revisions
Using isUnique validation of Cakephp, need to attach Mongodb.SqlCompatible behavior before saving. Here is sample code of controller::add() action.
public function add() {
if (!empty($this->data)) {
$this->Geo->create();
//need to attach behavior
$this->Geo->Behaviors->attach('Mongodb.SqlCompatible');
if ($this->Geo->save($this->data)) {
$this->flash(__('Geo saved.', true), array('action' => 'index'));
} else {
}
}
}
Here is Model::validate setting.
public $validate = array(
'title' => array(
'rule' => 'isUnique',
'required' => false
),
);