这是验证规则:
'name'=>array(
'Please enter customer\'s name'=>array(
'rule'=>'notEmpty',
'message'=>'Please enter customer\'s name'
),
'Unique' => array(
'rule' => array('nameIsUniqueForCompany'),
'message' => 'Customer with these initials already exists'
)
),
public function initialsAreUniqueForCompany($data){
$company_id = $this->data['Customer']['company_id'];
$initials = $this->data['Customer']['initials'];
if($this->find('first', array('conditions'=>array('initials'=>$initials, 'company_id'=>$company_id))))
{
return false;
}
return true;
}
问题是该规则应用于当前对象。假设我想更新一个名为“ABC”的客户,但我只是更改了他的电话号码。然后应用程序将查看名称 ABC 是否已经存在,它当然会找到它并且不会更新。
有任何想法吗?