protected function checkRelations(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$entityManager = $args->getEntityManager();
$entityName = (new \ReflectionClass($entity))->getShortName();
if (in_array($entityManager->getClassMetadata(get_class($entity))->name, $this->excludedEntities)) {
return;
}
$mappings = $entityManager->getClassMetadata(get_class($entity))->getAssociationMappings();
foreach ($mappings as $mapping) {
if ($mapping['type'] === ClassMetadataInfo::ONE_TO_MANY || $mapping['type'] === ClassMetadataInfo::MANY_TO_MANY) {
$targetEntityMeta = $entityManager->getClassMetadata($mapping['targetEntity']);
if ($targetEntityMeta->reflClass->getParentClass()) {
if (in_array($targetEntityMeta->reflClass->getParentClass()->name, $this->ignoredEntities)) {
continue;
}
}
$accessor = PropertyAccess::createPropertyAccessor();
$value = $accessor->getValue($entity, $mapping['fieldName']);
if (count($value) === 0) {
continue;
}
$exception = new HasRelationException();
$exception->setEntityName($entityName);
$exception->setEntity($entity);
$exception->setMapping($mapping);
throw $exception;
}
}
}