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

Wrong type inference for QueryBuilder::update and QueryBuilder::delete. #259

Closed
VincentLanglet opened this issue Jan 24, 2022 · 5 comments · Fixed by #260
Closed

Wrong type inference for QueryBuilder::update and QueryBuilder::delete. #259

VincentLanglet opened this issue Jan 24, 2022 · 5 comments · Fixed by #260

Comments

@VincentLanglet
Copy link
Contributor

The following code

$result = $this->getEntityManager()
            ->getRepository(ProductCrossSell::class)
            ->createQueryBuilder('pcs')
            ->where('pcs.id IN (:ids)')
            ->setParameter('ids', $ids)
            ->delete()
            ->getQuery()
            ->getResult();

\PHPStan\dumpType($result);

Is considering $result as an array. But it's an int: the number of deleted elements. Same with update()

It was introduce by #232 cc @arnaud-lb

@arnaud-lb
Copy link
Contributor

arnaud-lb commented Jan 24, 2022

Hi @VincentLanglet

I believe that there are two distinct issues here. The first one is that

$result = $this->getEntityManager()
            ->getRepository(ProductCrossSell::class)
            ->createQueryBuilder('pcs')
            ->where('pcs.id IN (:ids)')
            ->setParameter('ids', $ids)
            ->delete()
            ->getQuery()

may be Query<mixed>. Could you confirm ?

If that's the case, the second issue is that the type of Query<mixed>::getResult() should not be array because the query may be an INSERT or DELETE query.

@VincentLanglet
Copy link
Contributor Author

may be Query<mixed>. Could you confirm ?

Indeed Dumped type: Doctrine\ORM\Query<mixed>

@arnaud-lb
Copy link
Contributor

Thank you.

I'm fixing the second issue in #260.

I'm not sure about the cause of the first issue. What is the type of ->getRepository(ProductCrossSell::class) ? Could you confirm that the query is valid ?

@VincentLanglet
Copy link
Contributor Author

I'm not sure about the cause of the first issue. What is the type of ->getRepository(ProductCrossSell::class) ?

Dumped type: App\Repository\ProductCrossSellRepository<App\Entity\ProductCrossSell>  

Could you confirm that the query is valid ?

Yes, it's just a DELETE with a WHERE condition on ids.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants