Commit 3eb257c3 by Alexander Kochetov

Improve `exist` validator to support array attributes

parent e2f6a555
......@@ -89,21 +89,19 @@ class ExistValidator extends Validator
$params = [$targetAttribute => $object->$attribute];
}
foreach ($params as $value) {
if (is_array($value)) {
$this->addError($object, $attribute, Yii::t('yii', '{attribute} is invalid.'));
return;
}
}
$targetClass = $this->targetClass === null ? get_class($object) : $this->targetClass;
$query = $this->createQuery($targetClass, $params);
if (is_array($object->$attribute)) {
if ($query->count() !== count($object->$attribute)) {
$this->addError($object, $attribute, $this->message);
}
} else {
if (!$query->exists()) {
$this->addError($object, $attribute, $this->message);
}
}
}
/**
* @inheritdoc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment