protected function hasEntity($value, Constraint $constraint)
    {
        $repo = $this->em->getRepository($constraint->className);
        /** @var Entity $formEntity */
        $formEntity = $this->context->getRoot()->getData();
        $query = $repo->createQueryBuilder()
            ->setParameter('value', $value)
        ;
        foreach ((array) $constraint->fieldNames as $fieldName) {
            $query->orWhere($fieldName . ' = :value');
        }

        $entity = $repo->findOneWith($query);
        if ($entity === false) {
            return false;
        }
        if ($entity->getId() === $formEntity->getId()) {
            return false;
        }

        return true;
    }
protected function hasEntity($value, Constraint $constraint)
    {
        $repo = $this->em->getRepository($constraint->className);
        /** @var Entity $formEntity */
        $formEntity = $this->context->getRoot()->getData();
        $query = $repo->createQueryBuilder()
            ->setParameter('value', $value)
        ;
        foreach ((array) $constraint->fieldNames as $fieldName) {
            $query->orWhere($fieldName . ' = :value');
        }

        $entity = $repo->findOneWith($query);
        if ($entity === false) {
            return false;
        }
        if ($entity->getId() === $formEntity->getId()) {
            return false;
        }

        return true;
    }
protected function hasEntity ( $ value , Constraint $ constraint ) { $ repo = $ this -> em -> getRepository ( $ constraint -> className ) ; /** @var Entity $formEntity */ $ formEntity = $ this -> context -> getRoot ( ) -> getData ( ) ; $ query = $ repo -> createQueryBuilder ( ) -> setParameter ( 'value' , $ value ) ; foreach ( ( array ) $ constraint -> fieldNames as $ fieldName ) { $ query -> orWhere ( $ fieldName . ' = :value' ) ; } $ entity = $ repo -> findOneWith ( $ query ) ; if ( $ entity === false ) { return false ; } if ( $ entity -> getId ( ) === $ formEntity -> getId ( ) ) { return false ; } return true ; }
Check if the validating entity has a record with a matching field value.

@param mixed      $value
@param Constraint $constraint

@return bool
Check if the validating entity has a record with a matching field value .