I’m finding (using findOneBy) a singe row in my entity. Here’s the code:
$userown = $this->getDoctrine()->getRepository('GameShelfUsersBundle:Own')
->findOneBy(array(
'game' => $game->getId(),
'user' => $em->getRepository('GameShelfUsersBundle:User')->find($session->getId())
));
Now I pass it to template as userown. But when I try to print it in twig, using {{ userown.typo }}, it throws an error:
An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class Proxies\__CG__\GameShelf\UsersBundle\Entity\OwnState could not be converted to string in D:\!!XAMPP\htdocs\
My Entity is here.
Doctrine automatically resolves your foreign keys, so
$typois not a string but an object. As the error message tells you, this object cannot be converted to a string, so printing it fails.You can either implement the
__toString()method inside yourOwnStateEntity (it should return a string) or you print an actual property of the OwnState object:{{ userown.type.someProperty }}.