mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 23:50:38 +08:00
Fix for #13485
This commit is contained in:
committed by
Carsten Brandt
parent
72a690216a
commit
0df8020dd0
@@ -159,8 +159,12 @@ class UniqueValidator extends Validator
|
|||||||
// also there's no need to run check based on primary keys, when $targetClass is not the same as $model's class
|
// also there's no need to run check based on primary keys, when $targetClass is not the same as $model's class
|
||||||
$exists = $query->exists();
|
$exists = $query->exists();
|
||||||
} else {
|
} else {
|
||||||
// if current $model is in the database already we can't use exists()
|
// if current $model is in the dat1abase already we can't use exists()
|
||||||
$models = $query->select($targetClass::primaryKey())->limit(2)->createCommand()->queryAll();
|
if ($query instanceof \yii\db\ActiveQuery) {
|
||||||
|
$models = $query->select($targetClass::primaryKey())->limit(2)->asArray()->all();
|
||||||
|
} else {
|
||||||
|
$models = $query->limit(2)->asArray()->all();
|
||||||
|
}
|
||||||
$n = count($models);
|
$n = count($models);
|
||||||
if ($n === 1) {
|
if ($n === 1) {
|
||||||
$keys = array_keys($conditions);
|
$keys = array_keys($conditions);
|
||||||
|
|||||||
Reference in New Issue
Block a user