Getting a “true” object from a proxy object in doctrine2

前端 未结 11 1485
南笙
南笙 2021-02-01 13:50

Doctrine uses proxy objects to represent related objects in order to facilitate lazy loading. This is a really cool feature, but its causing an issue with something I am trying

11条回答
  •  太阳男子
    2021-02-01 14:26

    This is a little bit nasty workaround that issue :

    // $proxyObject = ...
    
    $em->detach($proxyObject);
    $entityObject = $em->find(, $proxyObject->getId());
    
    // now you have real entity and not the proxy (entityObject instead of proxyObject)
    

    after that you can replace proxy reference if you need to have it inside other entities

提交回复
热议问题