Symfony2 and Doctrine: how to fetch two different object for the same id?

后端 未结 2 1541
花落未央
花落未央 2021-01-18 11:33

I have this scenario:

  • Object A have some reference to other objects B,C,D
  • Object B have some reference to other objects A,F,G
  • Object C have so
2条回答
  •  星月不相逢
    2021-01-18 12:17

    Answer was less complex than I expected.

    It seem to be sufficent call $this->entity_manager->clear(); that will clear this entity map and force it to reload from database into a brand new object!

    $this->entity_manager->clear();
    $aCopy = $this->entity_manager
                           ->getRepository('MyBundle:A')
                           ->find($a->getId());
                $this->logger->debug('Original Obj: '.spl_object_hash($a));
                $this->logger->debug('Copied Obj:      '.spl_object_hash($aCopy));
    

    this will print

    [2013-02-08 12:07:20] app.DEBUG: Original Obj: 000000006523645c000000004b1160d1 [] [] [2013-02-08 12:07:20] app.DEBUG: Copied Obj: 00000000652366e3000000004b1160d1 [] []

提交回复
热议问题