-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Closed
Description
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);
}
Maybe related with
#7860
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels