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 to accomplish.
I have customized my user object so that they are all required to be related to a different object, which I will call city. This relationship is working fine.
I have a form that my user fills out to generate another object, street. Street is also related to the city object. Instead of having my user select the city when they fill out the form, I want to automatically set it before I persist the object to my database.
I tried using $event->setCity($user->getCity())
, but since $user->getCity() returns a proxy object, this generates an error. Is there a function I can call from the proxy object to get the real one?
Note: I am aware I can create a custom query with a join to force doctrine to actually load the related object, but since this is the user (using FOSUserBundle) that would be difficult to do properly.
question from:
https://stackoverflow.com/questions/8337754/getting-a-true-object-from-a-proxy-object-in-doctrine2 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…