https://trac.cakephp.org/ticket/2788
1. isUnique method, easily implemented in app wide app_model.php
2. ideally it SHOULD placed in Validation class
Implementation
--------------------------------
class AppModel extends Model{
/**
* Generic isUnique validation rule
* applicable for both add, edit action
*/
function isUnique($data, $field) {
$found = $this->find($this->name.".$field=\"".$data.'"');
$same = isset($this->id) && $found[$this->name]['id'] == $this-
>id;
return !$found || ($found && $same);
}
}
?>
Usage
--------------------------------------
var $validate = array(
'site_id' => VALID_NOT_EMPTY,
'name' => array('required' => VALID_NOT_EMPTY,
'unique' => array('rule' => array('isUnique','name'),
'message' => 'Object name already exist')
)
'otherField' => array('required' => VALID_NOT_EMPTY,
'unique' => array('rule' => array('isUnique','otherField'),
'message' => 'Object otherField already exist')
)
);
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---