Skip to content

Commit 9f0d833

Browse files
author
abluchet
committed
Fix #1959 do not join same association twice
1 parent 9d71217 commit 9f0d833

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

features/main/circular_reference.feature

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,29 @@ Feature: Circular references handling
6161
"@type": "CircularReference",
6262
"parent": "/circular_references/1",
6363
"children": [
64-
"/circular_references/1",
65-
"/circular_references/2"
64+
"/circular_references/1"
6665
]
6766
},
6867
"children": []
6968
}
7069
"""
70+
And I send a "GET" request to "/circular_references/1"
71+
Then the response status code should be 200
72+
And the JSON should be equal to:
73+
"""
74+
{
75+
"@context": "/contexts/CircularReference",
76+
"@id": "/circular_references/1",
77+
"@type": "CircularReference",
78+
"parent": "/circular_references/1",
79+
"children": [
80+
"/circular_references/1",
81+
{
82+
"@id": "/circular_references/2",
83+
"@type": "CircularReference",
84+
"parent": "/circular_references/1",
85+
"children": []
86+
}
87+
]
88+
}
89+
"""

src/Bridge/Doctrine/Orm/Extension/EagerLoadingExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,13 @@ private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInt
200200
$queryBuilder->addSelect($associationAlias);
201201
}
202202

203-
// Avoid recursion
203+
// Avoid recursive joins
204204
if ($mapping['targetEntity'] === $resourceClass) {
205-
$queryBuilder->addSelect($associationAlias);
205+
// Avoid joining the same association twice (see #1959)
206+
if (!\in_array($associationAlias, $queryBuilder->getAllAliases(), true)) {
207+
$queryBuilder->addSelect($associationAlias);
208+
}
209+
206210
continue;
207211
}
208212

0 commit comments

Comments
 (0)