public function beforeEntityDelete($entity, &$idx)
    {
        $this->undeleteReasons = [];

        $entityMetadata = $this->em->getClassMetadata(get_class($entity));

        $associations = $entityMetadata->getAssociationMappings();

        foreach ($associations as $association) {
            if (in_array('remove', $association['cascade'])) {
                continue; // Skip of cascading enabled
            }

            if (!in_array($association['type'], [ClassMetadata::ONE_TO_MANY])) {
                continue; // Handling only _TO_MANY relations
            }

            $propertyAccessor = new PropertyAccessor();
            $associationData = $propertyAccessor->getValue($entity, $association['fieldName']);

            if ($associationData instanceof Collection) {
                if ($associationData->count() > 0) {
                    $this->removeFromIdsArray($entityMetadata->getIdentifierValues($entity), $idx, $association);
                }
            } elseif ($associationData !== null) {
                $this->removeFromIdsArray($entityMetadata->getIdentifierValues($entity), $idx, $association);
            }
        }

        return $this->undeleteReasons;
    }