private function findFieldCriteriaStep2(array &$criteria, ObjectManager $em, ClassMetadata $class, $fieldName): void
    {
        if (null !== $criteria[$fieldName] && $class->hasAssociation($fieldName)) {
            /* Ensure the Proxy is initialized before using reflection to
             * read its identifiers. This is necessary because the wrapped
             * getter methods in the Proxy are being bypassed.
             */
            $em->initializeObject($criteria[$fieldName]);

            $relatedClass = $em->getClassMetadata($class->getAssociationTargetClass($fieldName));
            $relatedId = $relatedClass->getIdentifierValues($criteria[$fieldName]);

            if (\count($relatedId) > 1) {
                throw new ConstraintDefinitionException(
                    'Associated entities are not allowed to have more than one identifier field to be '.
                    'part of a unique constraint in: '.$class->getName().'#'.$fieldName
                );
            }

            $value = array_pop($relatedId);
            $criteria[$fieldName] = Util::getFormattedIdentifier($relatedClass, $criteria, $fieldName, $value);
        }
    }