/**
* @param object $object
*/
public function processIds($object)
{
$id = IdHelper::getId($object);
if ($id !== null && empty($id)) {
IdHelper::setId($object, null);
}
$class = get_class($object);
$reflection = new \ReflectionClass($class);
$em = $this->doctrine->getManagerForClass($class);
/** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata */
$metadata = $em->getMetadataFactory()->getMetadataFor($class);
// Look for relationships, compare against preloaded entity
foreach ($metadata->getAssociationNames() as $fieldName) {
$property = $reflection->getProperty($fieldName);
$property->setAccessible(true);
$value = $property->getValue($object);
if (!$value) {
continue;
}
if ($metadata->isCollectionValuedAssociation($fieldName)) {
foreach ($value as $v) {
$this->processIds($v);
}
}
}
}