Doctrine does not hydrates a query correctly! #6232

Closed
opened 2026-01-22 15:29:17 +01:00 by admin · 3 comments
Owner

Originally created by @engharb on GitHub (May 2, 2019).

Originally assigned to: @Ocramius on GitHub.

Current ORM version is: 2.6

Support Question

I have two entities with declared relationship as ManyToMany or else. But in my DQL query I want to define a JOIN WITH in order to hydrate the resulted objects of two different entities i.e as the following:
Entity_A Entity_B
a1 b1
a2 b2
a3 b1

my query:

$query = $this->createQueryBuilder('prod')
            ->select('a, b')
            ->innerJoin('App:B', 'b', Join::WITH,
                'a.xxx = b.xxx')
.....

            ->execute();

The result is :
array [
0 => a1,
1 => b1,
2 => a2,
3 => b2,
4 => a3,
5 => b1
]

But It should be or I want it to be as:
Array => [
0 => [a1, b1],
1 => [a2, b2],
3 => [a3, b1]
]

Why the query does not return a hydrated result correctly in case that there is no declared relationship between different entities?

Originally created by @engharb on GitHub (May 2, 2019). Originally assigned to: @Ocramius on GitHub. Current ORM version is: 2.6 ### Support Question I have two entities with declared relationship as ManyToMany or else. But in my DQL query I want to define a JOIN WITH in order to hydrate the resulted objects of two different entities i.e as the following: Entity_A Entity_B a1 b1 a2 b2 a3 b1 my query: ``` $query = $this->createQueryBuilder('prod') ->select('a, b') ->innerJoin('App:B', 'b', Join::WITH, 'a.xxx = b.xxx') ..... ->execute(); ``` The result is : array [ 0 => a1, 1 => b1, 2 => a2, 3 => b2, 4 => a3, 5 => b1 ] But It should be or I want it to be as: Array => [ 0 => [a1, b1], 1 => [a2, b2], 3 => [a3, b1] ] Why the query does not return a hydrated result correctly in case that there is no declared relationship between different entities?
admin added the Can't FixQuestionDQL labels 2026-01-22 15:29:17 +01:00
admin closed this issue 2026-01-22 15:29:17 +01:00
Author
Owner

@Ocramius commented on GitHub (May 2, 2019):

As confusing as it might seem, that is the correct hydration for arbitrary joins. Sadly, we cannot change that, as it would be a very subtle BC break.

@Ocramius commented on GitHub (May 2, 2019): As confusing as it might seem, that is the correct hydration for arbitrary joins. Sadly, we cannot change that, as it would be a very subtle BC break.
Author
Owner

@engharb commented on GitHub (May 2, 2019):

@Ocramius Do you have any workaround?

@engharb commented on GitHub (May 2, 2019): @Ocramius Do you have any workaround?
Author
Owner

@Ocramius commented on GitHub (May 2, 2019):

You can try hydrating with SELECT a AS key1, b AS key2 FROM ...: I don't remember what kind of structure that produces though.

@Ocramius commented on GitHub (May 2, 2019): You can try hydrating with `SELECT a AS key1, b AS key2 FROM ...`: I don't remember what kind of structure that produces though.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6232