class User extends AppModel {
public $validate = array(
'promotion_code' => array(
'rule' => array('limitDuplicates', 25),
'message' => 'This code has been used too many times.'
)
);
public function limitDuplicates($check, $limit) {
// $check will have value: array('promotion_code' => 'some-value')
// $limit will have value: 25
$existingPromoCount = $this->find('count', array(
'conditions' => $check,
'recursive' => -1
));
return $existingPromoCount < $limit;
}
}