Serialize relationships Doctrine

0

How do I json the relationships of an entity in doctrine? I've looked around and made a few attempts but nothing that worked until now.

I'm doing this 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);

Ticket class relationship with user:

/**
 * @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 any "trick" to do this? vlw

    
asked by anonymous 01.03.2016 / 23:01

1 answer

0

You just have to bring the user along with the ticket when executing the query . As for the rest of the code, nothing changes.

$list = $this
    ->getEm()
    ->createQuery('
        SELECT t, u
        FROM Ticket\Entity\Ticket t
        JOIN t.usuario u');
    
23.03.2016 / 11:26