How to make InnerJoin with related table?

0

Personal I have a class Arquivo that has a ManyToOne relationship with a Usuario class running right. I need to list all the data that is in the Arquivo s class including the relationships. How do I do this in Doctrine?

Class relationship Archive looks like this:

/**
 * @ORM\ManyToOne(targetEntity="JN\Entity\Usuarios\Usuario", cascade={"persist"})
 * @ORM\JoinColumn(name="usuario_id", referencedColumnName="id", onDelete="SET NULL")
 **/
private $usuario;

When I do this in doctrine I do not go back to the content of the relationship:

$ent = $this->em->getRepository( "JN\Entity\Arquivos\Arquivo" )
                ->createQueryBuilder('t')
                ->getQuery()
                ->getArrayResult();
    
asked by anonymous 04.03.2015 / 00:27

1 answer

0

Assemble your query as follows:

$ent = $this->em->getRepository("JN\Entity\Arquivos\Arquivo" )
    ->createQueryBuilder('t')
    ->join('t.usuario', 'u')
    ->getQuery()
    ->getResult();

The result will be a collection of entities of type JN\Entity\Arquivos\Arquivo . To iterate through these entities and get the user of each file do so:

foreach ($ent as $arquivo) {
    $arquivo->getUsuario();
}
    
04.03.2015 / 00:57