Skip to content

Commit

Permalink
Fix for yiisoft#13485
Browse files Browse the repository at this point in the history
  • Loading branch information
developeruz authored and cebe committed Feb 1, 2017
1 parent 72a6902 commit 0df8020
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions framework/validators/UniqueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ private function modelExists($targetClass, $conditions, $model)
// 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();
} else {
// if current $model is in the database already we can't use exists()
$models = $query->select($targetClass::primaryKey())->limit(2)->createCommand()->queryAll();
// if current $model is in the dat1abase already we can't use exists()
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);
if ($n === 1) {
$keys = array_keys($conditions);
Expand Down

0 comments on commit 0df8020

Please sign in to comment.