Commit 3eb257c3 by Alexander Kochetov

Improve `exist` validator to support array attributes

parent e2f6a555
...@@ -89,19 +89,17 @@ class ExistValidator extends Validator ...@@ -89,19 +89,17 @@ class ExistValidator extends Validator
$params = [$targetAttribute => $object->$attribute]; $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; $targetClass = $this->targetClass === null ? get_class($object) : $this->targetClass;
$query = $this->createQuery($targetClass, $params); $query = $this->createQuery($targetClass, $params);
if (!$query->exists()) { if (is_array($object->$attribute)) {
$this->addError($object, $attribute, $this->message); if ($query->count() !== count($object->$attribute)) {
$this->addError($object, $attribute, $this->message);
}
} else {
if (!$query->exists()) {
$this->addError($object, $attribute, $this->message);
}
} }
} }
......
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