Semantical Error - Doctrine createQueryBuilder

Asked

Viewed 198 times

1

But once I get caught using Doctrine.

I wanted to do it:

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 so:

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

is it happens that :

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

2 answers

3


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

So, your query that, in SQL, is 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, I usually use DQL):

$query = $this->createQueryBuilder('c')
    ->select('c', 'log')
    ->from('computador', 'c')
    ->join('c.log');
  • was exactly as utilzei. Thank you.

0

Do so:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.