Skip to content

Commit

Permalink
fixed broken UniqueValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
cebe committed Nov 22, 2013
1 parent 6995e8d commit ed98df5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions framework/yii/validators/UniqueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public function validateAttribute($object, $attribute)
$attributeName = $this->attributeName === null ? $attribute : $this->attributeName;

$attributes = $className::attributes();
if (!in_array($attribute, $attributes)) {
if (!in_array($attributeName, $attributes)) {
throw new InvalidConfigException("'$className' does not have an attribute named '$attributeName'.");
}

$query = $className::find();
$query->where([$attribute => $value]);
$query->where([$attributeName => $value]);

if (!$object instanceof ActiveRecord || $object->getIsNewRecord()) {
// if current $object isn't in the database yet then it's OK just to call exists()
Expand All @@ -82,7 +82,7 @@ public function validateAttribute($object, $attribute)

$n = count($objects);
if ($n === 1) {
if (in_array($attribute, $className::primaryKey())) {
if (in_array($attributeName, $className::primaryKey())) {
// primary key is modified and not unique
$exists = $object->getOldPrimaryKey() != $object->getPrimaryKey();
} else {
Expand Down

0 comments on commit ed98df5

Please sign in to comment.