0

I've got a strange problem with Doctrine Query, with Symfony 2.3

(by advance, sorry for the english/french terms in my queries .. :s )

When, in my controller, I launch a findAll() query on one of my Repositories, the following query is generated:

SELECT t0.id AS id1, t0.date AS date2, t0.projet_id AS projet_id3, t0.societe_id AS societe_id4, t0.user_id AS user_id5 FROM Estimate t0

Thus, I get all my columns including the ones involving relationships. But I need to add leftJoin on my query. I created a custom query:

$qb = $this->createQueryBuilder('e')
    ->addSelect('e')
    ->leftJoin('e.works', 'w')
    ->addSelect('w')
    ->leftJoin('w.tache', 't')
    ->addSelect('t')
    ->leftJoin('t.groupetache', 'g')
    ->addSelect('g')
    ;

and now, I got all the joined column, but for my main table "Estimate", the query only returns id and date (the following query is generated:)

SELECT e0_.id AS id0, e0_.date AS date1, w1_.id AS id4, w1_.description AS description5, w1_.prix_ha AS prix_ha6, w1_.prix_vente AS prix_vente7, t2_.id AS id8, t2_.nom AS nom9, t2_.prix_achat AS prix_achat10, g3_.id AS id11, g3_.nom AS nom12 FROM Estimate e0_ LEFT JOIN Work w1_ ON e0_.id = w1_.estimate_id LEFT JOIN Tache t2_ ON w1_.tache_id = t2_.id LEFT JOIN GroupeTaches g3_ ON t2_.groupetache_id = g3_.id

Am I missing a point ?

There's a way to get all my main table fields, + joined fields right ?

My "manual" query on Sequel Pro returns what I want, I tried to change my query with a DQL one, like this :

$query = $this->getEntitymanager()
    ->createQuery('
        SELECT e0_.id AS id0, e0_.date AS date1, e0_.id AS id2, e0_.date AS date3,
        e0_.projet_id AS projet_id3, e0_.societe_id AS societe_id4, e0_.user_id AS user_id5,
        w1_.id AS id4, w1_.description AS description5, w1_.prix_ha AS prix_ha6, w1_.prix_vente AS prix_vente7,
        t2_.id AS id8, t2_.nom AS nom9, t2_.prix_achat AS prix_achat10, g3_.id AS id11, g3_.nom AS nom12
        FROM EcomCrmBundle:Estimate e0_
        LEFT JOIN EcomCrmBundle:Work w1_ WITH e0_.id = w1_.estimate_id
        LEFT JOIN EcomCrmBundle:Tache t2_ WITH w1_.tache_id = t2_.id
        LEFT JOIN EcomCrmBundle:GroupeTaches g3_ WITH t2_.groupetache_id = g3_.id');

but I've got an error, saying Estimate doesn't have a projet_id field :(

Thanks in advance for your help.

4

1 回答 1

1

我只是在猜测,但是您使用什么方法来检索结果?获取数组结果()?尝试使用 getResult()。它应该选择“估计”中的每一行。

于 2013-08-16T12:45:46.237 回答