/** * Remove any unreferenced non aggregate root entity * * @param object $object * @param string $propertyName * @param array $propertyMetaData * @return void */ protected function removeDeletedReference($object, $propertyName, $propertyMetaData) { $previousValue = $this->persistenceSession->getCleanStateOfProperty($object, $propertyName); if ($previousValue !== null && is_array($previousValue) && isset($previousValue['value']['identifier']) && $this->reflectionService->getClassSchema($propertyMetaData['type'])->getModelType() === ClassSchema::MODELTYPE_ENTITY && $this->reflectionService->getClassSchema($propertyMetaData['type'])->isAggregateRoot() === false) { $object = $this->persistenceSession->getObjectByIdentifier($previousValue['value']['identifier']); if (!$this->visitedDuringPersistence->contains($object)) { $this->removeEntity($object); } } }