Symfony ManyToOne relationship getter returns empty object

余生长醉 提交于 2019-12-05 09:57:55

This is because the proxy object is not initialised yet. One way to initialise it, is by querying the object e.g. $doctor->getId(). If you dump the object after that, you'll see that all the attributes are 'visible'

The answer of Thomas K worked for me in my own Bundle. If I translate what I did :

$myPaciente = $em->getRepository('MyBundle:Paciente')->findOneBy(array('numColegiado' => $value));

I add $myPaciente->getDoctor()->getName();

Then the initialisation was done and I could dump $myPaciente with all the information about the doctor related to it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!