Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setFetchMode() is ignored - Exception eager Fetch Join With Not Allowed #11128

Closed
insekticid opened this issue Dec 20, 2023 · 0 comments
Closed

Comments

@insekticid
Copy link

insekticid commented Dec 20, 2023

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
#7860

@insekticid insekticid changed the title setFetchMode() is ignored - eager Fetch Join With Not Allowed setFetchMode() is ignored - Exception eager Fetch Join With Not Allowed Dec 20, 2023
Abbraxar pushed a commit to Abbraxar/orm that referenced this issue Jan 19, 2024
…f fetch-mode EAGER and WITH condition.

This fixes a bug that arises when an entity relation is mapped with fetch-mode EAGER but setFetchMode LAZY (or anything that is not EAGER) has been used on the query. If the query use WITH condition, an exception is incorrectly raised (Associations with fetch-mode=EAGER may not be using WITH conditions).
Fixes doctrine#11128
aprat84 pushed a commit to aprat84/orm that referenced this issue May 6, 2024
…f fetch-mode EAGER and WITH condition.

This fixes a bug that arises when an entity relation is mapped with fetch-mode EAGER but setFetchMode LAZY (or anything that is not EAGER) has been used on the query. If the query use WITH condition, an exception is incorrectly raised (Associations with fetch-mode=EAGER may not be using WITH conditions).
Fixes doctrine#11128
aprat84 pushed a commit to aprat84/orm that referenced this issue May 23, 2024
…f fetch-mode EAGER and WITH condition.

This fixes a bug that arises when an entity relation is mapped with fetch-mode EAGER but setFetchMode LAZY (or anything that is not EAGER) has been used on the query. If the query use WITH condition, an exception is incorrectly raised (Associations with fetch-mode=EAGER may not be using WITH conditions).
Fixes doctrine#11128
greg0ire pushed a commit to greg0ire/doctrine-orm that referenced this issue May 25, 2024
…f fetch-mode EAGER and WITH condition.

This fixes a bug that arises when an entity relation is mapped with fetch-mode EAGER but setFetchMode LAZY (or anything that is not EAGER) has been used on the query. If the query use WITH condition, an exception is incorrectly raised (Associations with fetch-mode=EAGER may not be using WITH conditions).
Fixes doctrine#11128
greg0ire pushed a commit to aprat84/orm that referenced this issue May 25, 2024
…f fetch-mode EAGER and WITH condition.

This fixes a bug that arises when an entity relation is mapped with fetch-mode EAGER but setFetchMode LAZY (or anything that is not EAGER) has been used on the query. If the query use WITH condition, an exception is incorrectly raised (Associations with fetch-mode=EAGER may not be using WITH conditions).
Fixes doctrine#11128
greg0ire added a commit that referenced this issue May 30, 2024
Consider usage of setFetchMode when checking for simultaneous usage of fetch-mode EAGER and WITH condition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant