diff --git a/validators/EMongoExistValidator.php b/validators/EMongoExistValidator.php index 6f4b0c0..e483f00 100644 --- a/validators/EMongoExistValidator.php +++ b/validators/EMongoExistValidator.php @@ -74,10 +74,12 @@ protected function validateAttribute($object, $attribute) $attributeName = $this->attributeName === null ? $attribute : $this->attributeName; $finder = EMongoDocument::model($className); - $criteria = array($attributeName => $this->mongoId ? new MongoId($value) : $value); + $criteria = $this->criteria; + $criteria[$attributeName] = $this->mongoId ? new MongoId($value) : $value; + if(!$finder->exists($criteria)){ $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" is invalid.'); $this->addError($object, $attribute, $message, array('{value}' => CHtml::encode($value))); } } -} \ No newline at end of file +}