tags:

views:

25

answers:

2

Hello,

I am using this to validate a form field

$valid = $this->isUnique(array($fieldName1 => $data, $fieldName2 => 'Y'));

executing this the query is coming like this:

SELECT COUNT(*) AS count FROM users AS User WHERE ((User.emailid = ('[email protected]')) OR (User.isdeleted = 'Y'))

I just need to change that "OR" to "AND".

Please help me!!!!

A: 

I have no idea why you are assigning your validation to a variable. Otherwise all your validation should be done inside your model in the validate array.

Take a look at the book, http://book.cakephp.org/view/1152/Core-Validation-Rules#isUnique-1166

If you are calling it using AJAX or similar where the model isn't being called as part of a save() you can always

$this->Model->set($this->data);
if($this->Model->validates($this->data){
  // Validation passed
}else{
  // Process validation errors, using
  $this->Model->invalidFields;
}
DavidYell
+1  A: 

The API documentation is always a good read:

Model::isUnique

"Returns false if any fields passed match any (by default, all if $or = false) of their matching values."

Parameters:

array $fields required
Field/value pairs to search (if no values specified, they are pulled from $this->data)

boolean $or optional, true
If false, all fields specified must match in order for a false return value

Return:
boolean False if any records matching any fields are found

deceze