src/Doctrine/ORM/CascadingRelationChecker.php
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;
    }
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;
    }
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 ; }
Hande entity relations before trying to remove it.

@param mixed $entity a Doctrine entity object
@param array $idx    list of entity ids to be removed

@return
Hande entity relations before trying to remove it .