Open SergeC opened 11 months ago
Assuming $this
is an entityrepository instance, createQueryBuilder
already calls select
internally. With your call, you're replacing that select, making sure j.id
is no longer selected.
In this use-case, I fetch only one column. Which means I need to specify it in select. Doctrine should automatically add indexing column to select statement. Even when I add indexing column to select - nothing changes.
Huh, I did not expect that. Maybe it has to do with getSingleColumnResult()
. Can you try other possibilities?
I meant with j.id
selected
This adds id to the result set along with array keys.
Okay. This means this issue really is about index by + getSingleColumnResult
.
I dont understand, where is index by configured here? Maybe i missef it, but this is only a non entity query here, getSingleColumnResult has no index by behavior afair
The second argument of EntityRepository::createQueryBuilder()
configures it:
@greg0ire @beberlei Any update on this? Any other info needed from my side?
I just stumbled upon this, good thing I decided to google it.
It is stupid that something like this happens; one would think that indexBy
is added implicitly regardless of what the user does with select()
, because it is REQUIRED by the code. It should NOT be overridable by user.
I was wondering why my "account balance mapped by account ID" query was returning 0-indexed results, made no goddamn sense, and the subsequent code was clearly doing the wrong thing, when it absolutely shouldn't have. Turns out the problem wasn't in my code, but in Doctrine being dumb yet again... Such an overcomplicated mass of code, and yet.
@greg0ire Hello. Anything new on this issue?
@rasstislav not as far as I can tell. Do you want to work on a fix?
Bug Report
Summary
QueryBuilder ignores indexBy argument and returns the result set indexed by PHP's array-keys.
Current behavior
QueryBuilder returns the result set indexed by PHP's array-keys.
How to reproduce
Expected behavior
QueryBuilder should return the result set indexed by values in the database, specified in the 2nd argument to
createQueryBuilder
.Installed dependencies:
Actual result: Expected result: