Use low-level query in UniqueValidator (#13461)

Fixes #13453, relates to #13098
This commit is contained in:
Elvira Sheina
2017-01-28 17:38:06 +02:00
committed by Alexander Makarov
parent 015f14e374
commit 240bca515a
2 changed files with 3 additions and 3 deletions

View File

@ -160,8 +160,7 @@ class UniqueValidator extends Validator
$exists = $query->exists();
} else {
// if current $model is in the database already we can't use exists()
/** @var $models ActiveRecordInterface[] */
$models = $query->limit(2)->all();
$models = $query->select($targetClass::primaryKey())->limit(2)->createCommand()->queryAll();
$n = count($models);
if ($n === 1) {
$keys = array_keys($conditions);
@ -173,7 +172,7 @@ class UniqueValidator extends Validator
$exists = $model->getOldPrimaryKey() != $model->getPrimaryKey();
} else {
// non-primary key, need to exclude the current record based on PK
$exists = reset($models)->getPrimaryKey() != $model->getOldPrimaryKey();
$exists = $models[0] != $model->getOldPrimaryKey(true);
}
} else {
$exists = $n > 1;