/** * * @param object $entity */ protected function prepareIndexData() { foreach ($this->queuedInserts as $entity) { foreach ($this->cm->getAssociationNames() as $field) { $association = $this->cm->associationMappings[$field]; if (ClassMetadata::REFERENCE_ONE === $association['type']) { $associationObject = $this->cm->getFieldValue($entity, $field); if ($associationObject) { $this->queuedIndexInserts[get_class($entity)][] = ['fields' => [$field => $associationObject->getId()], 'target' => $this->cm->getIdentifierValue($entity)]; } } } } foreach ($this->queuedUpdates as $entity) { foreach ($this->cm->getAssociationNames() as $field) { $association = $this->cm->associationMappings[$field]; if (ClassMetadata::REFERENCE_ONE === $association['type']) { $associationObject = $this->cm->getFieldValue($entity, $field); if ($associationObject) { $this->queuedIndexInserts[get_class($entity)][] = ['fields' => [$field => $associationObject->getId()], 'target' => $this->cm->getIdentifierValue($entity)]; } } } } foreach ($this->queuedDeletes as $entity) { foreach ($this->cm->getAssociationNames() as $field) { $association = $this->cm->associationMappings[$field]; if (ClassMetadata::REFERENCE_ONE === $association['type']) { $associationObject = $this->cm->getFieldValue($entity, $field); if ($associationObject) { $this->queuedIndexDeletes[get_class($entity)][] = ['fields' => [$field => $associationObject->getId()], 'target' => $this->cm->getIdentifierValue($entity)]; } } } } }
/** * * @param object $entity * @param string $oid * @param ClassMetadata $cm * @return integer */ public function getState($entity, $oid, ClassMetadata $cm) { if (isset($this->states[$oid])) { return $this->states[$oid]; } $id = $cm->getIdentifierValue($entity); if (!$id) { return UnitOfWork::STATE_NEW; } if (null !== $this->tryGetById($id, $cm->rootName)) { return UnitOfWork::STATE_DETACHED; } return UnitOfWork::STATE_NEW; }