mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-27 04:10:30 +08:00
fixed broken UniqueValidator
This commit is contained in:
@@ -65,12 +65,12 @@ class UniqueValidator extends Validator
|
|||||||
$attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
|
$attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
|
||||||
|
|
||||||
$attributes = $className::attributes();
|
$attributes = $className::attributes();
|
||||||
if (!in_array($attribute, $attributes)) {
|
if (!in_array($attributeName, $attributes)) {
|
||||||
throw new InvalidConfigException("'$className' does not have an attribute named '$attributeName'.");
|
throw new InvalidConfigException("'$className' does not have an attribute named '$attributeName'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $className::find();
|
$query = $className::find();
|
||||||
$query->where([$attribute => $value]);
|
$query->where([$attributeName => $value]);
|
||||||
|
|
||||||
if (!$object instanceof ActiveRecord || $object->getIsNewRecord()) {
|
if (!$object instanceof ActiveRecord || $object->getIsNewRecord()) {
|
||||||
// if current $object isn't in the database yet then it's OK just to call exists()
|
// if current $object isn't in the database yet then it's OK just to call exists()
|
||||||
@@ -82,7 +82,7 @@ class UniqueValidator extends Validator
|
|||||||
|
|
||||||
$n = count($objects);
|
$n = count($objects);
|
||||||
if ($n === 1) {
|
if ($n === 1) {
|
||||||
if (in_array($attribute, $className::primaryKey())) {
|
if (in_array($attributeName, $className::primaryKey())) {
|
||||||
// primary key is modified and not unique
|
// primary key is modified and not unique
|
||||||
$exists = $object->getOldPrimaryKey() != $object->getPrimaryKey();
|
$exists = $object->getOldPrimaryKey() != $object->getPrimaryKey();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user