Skip to content

Commit f1ce0e1

Browse files
committed
Fixes issue yiisoft#428 Allowing UniqueValidator to be used with non-AR models.
1 parent 458615f commit f1ce0e1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

framework/yii/validators/UniqueValidator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Yii;
1111
use yii\base\InvalidConfigException;
12+
use yii\db\ActiveRecord;
1213

1314
/**
1415
* CUniqueValidator validates that the attribute value is unique in the corresponding database table.
@@ -71,7 +72,7 @@ public function validateAttribute($object, $attribute)
7172
$query = $className::find();
7273
$query->where(array($column->name => $value));
7374

74-
if ($object->getIsNewRecord()) {
75+
if (!$object instanceof ActiveRecord || $object->getIsNewRecord()) {
7576
// if current $object isn't in the database yet then it's OK just to call exists()
7677
$exists = $query->exists();
7778
} else {

0 commit comments

Comments
 (0)