0
How do I do a json with Entity relationships in Doctrine? I’ve looked around and made a few attempts but nothing that has worked so far.
I’m doing so and returns the normal json(without the relationships):
$list = $this->getEm()->createquery('select u from Ticket\Entity\Ticket u');
$query = $list->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
return new \Zend\View\Model\JsonModel($query);
Relationship of the Ticket with user class:
/**
* @ORM\ManyToOne(targetEntity="Ticket\Entity\Usuario", inversedBy="ticket")
* @ORM\JoinColumn(name="usuario_id", referencedColumnName="id")
*
*/
protected $usuario;
output:
[{"id":41,"description":"teste"},{"id":38,"description":"teste1"}]
Is there a "trick" to this? vlw
What do you want to do? Bring user information along with the ticket?
– Rodrigo Rigotti