Semantical Error - Doctrine createQueryBuilder

1

But once I get caught using doctrine usage.

I wanted to do this:

SELECT c.nm_computador, c.te_ip_computador, log.usuario, log.data
FROM computador c
INNER JOIN log_user_logado log ON c.id_computador = log.id_computador;

But I do this:

    $query = $this->createQueryBuilder('c')
        ->select('c.nmComputador', 'c.teIpComputador', 'log.data', 'log.usuario')
        ->from('computador', 'c')
        ->innerJoin('log.idComputador', 'WITH', 'c.idComputador');

This happens:

[Semantical Error] line 0, col 124 near '.Computer': Error: Identification Variable log used in join path expression but was not defined before.

    
asked by anonymous 07.11.2014 / 18:32

2 answers

3

When you have reproduced in your application the relationships between tables, Doctrine already knows which columns to use to relate one table to another. Therefore, it is not necessary to specify the columns in the JOINs of a DQL.

So, your SQL query looks like this:

SELECT c.nm_computador, c.te_ip_computador, log.usuario, log.data
FROM computador c
INNER JOIN log_user_logado log ON c.id_computador = log.id_computador;

... would look like this in DQL:

SELECT c, lot
FROM computador c
JOIN c.lot

... and so by QueryBuilder (if I'm not mistaken, because I usually use DQL):

$query = $this->createQueryBuilder('c')
    ->select('c', 'log')
    ->from('computador', 'c')
    ->join('c.log');
    
17.03.2015 / 13:13
0

Do this:

$query = $this->doctrine->getManager()
    ->createQuery('SELECT c.nmComputador, c.teIpComputador, log.data, log.usuario
                       FROM SuaBundleOndeEstaoAsEntidades:log JOIN log.idComputador c');
    
16.12.2014 / 23:20