protected function validateValue($value)
{
if ($this->targetClass === null) {
throw new InvalidConfigException('The "targetClass" property must be set.');
}
if (!is_string($this->targetAttribute)) {
throw new InvalidConfigException('The "targetAttribute" property must be configured as a string.');
}
$query = $this->createQuery($this->targetClass, [$this->targetAttribute => $value]);
if (is_array($value)) {
if (!$this->allowArray) {
return [$this->message, []];
}
return $query->count("DISTINCT [[{$this->targetAttribute}]]") == count($value) ? null : [$this->message, []];
} else {
return $query->exists() ? null : [$this->message, []];
}
}