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
    ),
  );
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.