code: private function queryValueExists($query, $value)
      {
          if (is_array($value)) {
              return $query->count("DISTINCT [[$this->targetAttribute]]") == count($value) ;
          }
          return $query->exists();
      }
docs: Run query to check if value exists
  
  @param QueryInterface $query
  @param mixed $value the value to be checked
  @return bool