Skip to content

Commit

Permalink
Merge pull request #11445 from aprat84/gh-11128
Browse files Browse the repository at this point in the history
Consider usage of setFetchMode when checking for simultaneous usage of fetch-mode EAGER and WITH condition
  • Loading branch information
greg0ire authored May 30, 2024
2 parents 4a01a76 + 9696c34 commit e063926
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,9 @@ public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joi
}
}

if ($relation['fetch'] === ClassMetadata::FETCH_EAGER && $condExpr !== null) {
$fetchMode = $this->query->getHint('fetchMode')[$assoc['sourceEntity']][$assoc['fieldName']] ?? $relation['fetch'];

if ($fetchMode === ClassMetadata::FETCH_EAGER && $condExpr !== null) {
throw QueryException::eagerFetchJoinWithNotAllowed($assoc['sourceEntity'], $assoc['fieldName']);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Tests/ORM/Functional/EagerFetchCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public function testSubselectFetchJoinWithNotAllowed(): void
$query->getResult();
}

public function testSubselectFetchJoinWithAllowedWhenOverriddenNotEager(): void
{
$query = $this->_em->createQuery('SELECT o, c FROM ' . EagerFetchOwner::class . ' o JOIN o.children c WITH c.id = 1');
$query->setFetchMode(EagerFetchChild::class, 'owner', ORM\ClassMetadata::FETCH_LAZY);

$this->assertIsString($query->getSql());
}

public function testEagerFetchWithIterable(): void
{
$this->createOwnerWithChildren(2);
Expand Down

0 comments on commit e063926

Please sign in to comment.