private function checkTargetRelationExistence($model, $attribute)
    {
        $exists = false;
        /** @var ActiveQuery $relationQuery */
        $relationQuery = $model->{'get' . ucfirst($this->targetRelation)}();

        if ($this->filter instanceof \Closure) {
            call_user_func($this->filter, $relationQuery);
        } elseif ($this->filter !== null) {
            $relationQuery->andWhere($this->filter);
        }

        if ($this->forceMasterDb && method_exists($model::getDb(), 'useMaster')) {
            $model::getDb()->useMaster(function() use ($relationQuery, &$exists) {
                $exists = $relationQuery->exists();
            });
        } else {
            $exists = $relationQuery->exists();
        }


        if (!$exists) {
            $this->addError($model, $attribute, $this->message);
        }
    }