Skip to content

Commit

Permalink
Option "caseSensitive" has been added to "CExistValidator".
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Jun 25, 2012
1 parent d4903d1 commit 1e0d2ba
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion framework/validators/CExistValidator.php
Expand Up @@ -29,6 +29,11 @@
class CExistValidator extends CValidator
{
/**
* @var boolean whether the comparison is case sensitive. Defaults to true.
* Note, by setting it to false, you are assuming the attribute type is string.
*/
public $caseSensitive=true;
/**
* @var string the ActiveRecord class name that should be used to
* look for the attribute value being validated. Defaults to null,
* meaning using the ActiveRecord class of the attribute being validated.
Expand Down Expand Up @@ -82,7 +87,7 @@ protected function validateAttribute($object,$attribute)
$criteria->mergeWith($this->criteria);
$tableAlias = empty($criteria->alias) ? $finder->getTableAlias(true) : $criteria->alias;
$valueParamName = CDbCriteria::PARAM_PREFIX.CDbCriteria::$paramCount++;
$criteria->addCondition("{$tableAlias}.{$columnName}={$valueParamName}");
$criteria->addCondition($this->caseSensitive ? "{$tableAlias}.{$columnName}={$valueParamName}" : "LOWER({$tableAlias}.{$columnName})=LOWER({$valueParamName})");
$criteria->params[$valueParamName] = $value;

if(!$finder->exists($criteria))
Expand Down

0 comments on commit 1e0d2ba

Please sign in to comment.