Created
May 16, 2011 05:42
-
-
Save heptat/973979 to your computer and use it in GitHub Desktop.
validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validator::add('uniqueFieldForClient', function($value, $format = null, $options = array()) { | |
$class = $options['class']; | |
$field = $options['field']; | |
$conditions = array($field => $value); | |
if (isset($options['values']['id'])) { | |
$conditions[] = 'id != ' . $options['values']['id']; | |
} | |
// TODO should I throw an exception if client_id is missing? otherwise it's | |
// up to the models that use this validator to also validate for requiring | |
// client_id | |
$conditions['client_id'] = $options['values']['client_id']; | |
echo '<pre>'; | |
print_r($conditions); | |
echo '</pre>'; | |
$record = $class::find('first', array('conditions' => $conditions)); | |
return !(bool) $record; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment