getPartialReference() public method

The returned reference may be a partial object if the entity is not yet loaded/managed. If it is a partial object it will not initialize the rest of the entity state on access. Thus you can only ever safely access the identifier of an entity obtained through this method. The use-cases for partial references involve maintaining bidirectional associations without loading one side of the association or to update an entity without loading it. Note, however, that in the latter case the original (persistent) entity data will never be visible to the application (especially not event listeners) as it will never be loaded in the first place.
public getPartialReference ( string $entityName, mixed $identifier ) : object
$entityName string The name of the entity type.
$identifier mixed The entity identifier.
return object The (partial) entity reference.
 function it_should_delete_entity(ManagerRegistry $registry, EntityManager $em)
 {
     $em->getPartialReference('foo', 1)->willReturn(42);
     $em->remove(42)->shouldBeCalled();
     $em->flush()->shouldBeCalled();
     $registry->getManager(null)->willReturn($em);
     $this->setRegistry($registry);
     $this->delete(1)->shouldBe(true);
 }
Exemplo n.º 2
0
 /**
  * Delete an Entity according to given (list of) id(s)
  * @param type $ids array/single
  * @return boolean
  */
 function delete($ids)
 {
     try {
         if (!is_array($ids)) {
             $ids = array($ids);
         }
         foreach ($ids as $id) {
             $entity = $this->em->getPartialReference($this->entity, $id);
             $this->em->remove($entity);
         }
         $this->em->flush();
         return TRUE;
     } catch (Exception $err) {
         log_message("error", $err->getMessage(), false);
         return FALSE;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getPartialReference($entityName, $identifier)
 {
     return $this->wrapped->getPartialReference($entityName, $identifier);
 }
Exemplo n.º 4
0
 /**
  * {@inheritDoc}
  *
  * @static 
  */
 public static function getPartialReference($entityName, $identifier)
 {
     return \Doctrine\ORM\EntityManager::getPartialReference($entityName, $identifier);
 }
Exemplo n.º 5
0
 /**
  * @param \Sgdoce\Model\Entity\ArtefatoImagem $artefatoImagemEntity
  * @param \Doctrine\ORM\EntityManager $entityManager
  * @return void
  */
 private function _fillSessionInformation(ArtefatoImagemEntity $artefatoImagemEntity, EntityManager $entityManager)
 {
     $pessoaEntity = $entityManager->getPartialReference('app:VwPessoa', \Core_Integration_Sica_User::getPersonId());
     $unidadeOrgEntity = $entityManager->getPartialReference('app:VwUnidadeOrg', \Core_Integration_Sica_User::getUserUnit());
     $artefatoImagemEntity->setSqPessoa($pessoaEntity);
     $artefatoImagemEntity->setSqUnidadeOrg($unidadeOrgEntity);
 }