Repository: doctrine/orm (php)

Issue:
setFetchMode() is ignored - Exception eager Fetch Join With Not Allowed
```
Entity/Category.php

#[ORM\Entity]
class Category
{
    #[ORM\Id]
    #[ORM\Column(type: 'integer')]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    private int $id;

    #[ORM\ManyToOne(targetEntity: 'Category', fetch: 'EAGER')]
    #[ORM\JoinColumn(name: 'root_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
    private ?Category $root = null;
}
```

Query
```
$qb = $this->createQueryBuilder('content')
            ->join('content.category', 'category')
            ->join('category.root', 'categoryRoot', Expr\Join::WITH, 'categoryRoot = :root')
            ->setParameter('root', $host->getCategory());

$query = $qb->getQuery();
$query->setFetchMode(Category::class, 'categoryRoot', ClassMetadata::FETCH_LAZY);
```

Result
```
Doctrine\ORM\Query\QueryException

Associations with fetch-mode=EAGER may not be using WITH conditions in
             "[App\Entity\Category]"
```

There should be check over SqlWalker::getQuery()->getHint('fetchMode') in case you override fetchMode()
Maybe there is a bug in $relation->fetch, where fetchMode should be propagated from hints?

```
if ($relation->fetch === ClassMetadata::FETCH_EAGER && $condExpr !== null) {
            throw QueryException::eagerFetchJoinWithNotAllowed($assoc->sourceEntity, $assoc->fieldName);
}
```

https://github.com/doctrine/orm/blame/28d03e41f7b58781c516404bf179806e10a84ec5/lib/Doctrine/ORM/Query/SqlWalker.php#L897

Maybe related with
https://github.com/doctrine/orm/issues/7860

Pull request:
Consider usage of setFetchMode when checking for simultaneous usage of fetch-mode EAGER and WITH condition
Fixes #11128.
Copy of #11174, author can't complete it right now.

Should be merged up to v3.1

Patch:
diff --git a/src/Query/SqlWalker.php b/src/Query/SqlWalker.php
index 4948be465..4c25fb63a 100644
--- a/src/Query/SqlWalker.php
+++ b/src/Query/SqlWalker.php
@@ -1062,7 +1062,9 @@ class SqlWalker implements TreeWalker
             }
         }
 
-        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']);
         }
 


Test patch:
diff --git a/tests/Tests/ORM/Functional/EagerFetchCollectionTest.php b/tests/Tests/ORM/Functional/EagerFetchCollectionTest.php
index ff0eab56d..88397c6a1 100644
--- a/tests/Tests/ORM/Functional/EagerFetchCollectionTest.php
+++ b/tests/Tests/ORM/Functional/EagerFetchCollectionTest.php
@@ -88,6 +88,14 @@ class EagerFetchCollectionTest extends OrmFunctionalTestCase
         $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);