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

Dynamic return type extension for EntityRepository::createQueryBuilder() not working? #465

Open
Wrongusername opened this issue Jul 31, 2023 · 0 comments

Comments

@Wrongusername
Copy link

Regarding
#66
and solution for it
#140

Issue description obviously produces expectation that solution would let you validate query builders created using (1)RepositoryClass::createQueryBuilder as a common use case, and not just ones from (2) ->getEntityManager()->createQueryBuilder()

But PR "solving" it is less clear on what it does.
In practice all i get with (1) is 'Could not analyse QueryBuilder with dynamic arguments.'.
RepositoryClass::createQueryBuilder naturally accepts alias and optional indexBy as opposed to ->getEntityManager()->createQueryBuilder(), so i guess it's "dynamic"

Even if that is intended to (not) work like that it's normally not even possible to realize something is wrong, as reportDynamicQueryBuilders is false by default, so for average user with repo-based queries using createQueryBuilder extension just silently fails to do any validation, which is a very weird decision and takes long time to debug.

class UserRepository extends EntityRepository
{
    public function findWorks(): User
    {
        return $this
            ->getEntityManager()
            ->createQueryBuilder()
            ->select('u')
            ->from(User::class, 'u')
            ->andWhere('u.dsdsf = :id')
            ->setParameter('id', 1)
            ->getQuery()
            ->getResult();
    }

    public function findFailDynamic(): User
    {
        return $this->createQueryBuilder('u')
            ->select('u')
            ->andWhere('u.asdfd = :id')
            ->setParameter('id', 1)
            ->getQuery()
            ->getResult();
    }
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