T. Perchec
T. Perchec

Reputation: 65

Doctrine query builder wrong results

I just came across a really annoying thing. I have a queryBuilder :

$queryBuilder
    ->select('a')
    ->addSelect('am')
    ->addSelect('m')
    ->addSelect('c')
    ->addSelect('t')
    ->leftJoin('a.articleMedias', 'am')
    ->leftJoin('am.media', 'm')
    ->leftJoin('a.categories', 'c')
    ->leftJoin('a.translations', 't')
    ->add('where', $queryBuilder->expr()->in('a.site', $ids))
;

When i get the results i get 192 objects. The problem is that when i dump the sql and execute it directly into the db, i get 529 objects. But it's the same query !

Does someone know the cause for this gap between the two results ?

EDIT : found something. When i do a count query, i get 203 results but when i do a normal one and count the results i get 192 results. Does it mean doctrine has a max vars or something ?

EDIT 2 : it seems like it was an inheritance problem specific to my application. Thanks again for helping me.

Upvotes: 2

Views: 945

Answers (1)

Fuzzzzel
Fuzzzzel

Reputation: 1773

The most likely answer to this is, that you do not get 529 Objects, but 529 rows of which 192 objects are built (because of the left joins).

When putting the query directly into the db you must count the unique (or in terms of SQL: DISTINCT rows of your object a. Depending on your ID column change the query that you dump to SELECT DISTINCT <you_primary_key_column>, <rest of your query> This result should give you 192 rows which matches your 192 objects.

If not, could you please post your resulting query?

Upvotes: 2

Related Questions