-
-
Notifications
You must be signed in to change notification settings - Fork 341
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
[Autocomplete] Don't add WHERE IN criteria without params #561
Conversation
norkunas
commented
Nov 25, 2022
Q | A |
---|---|
Bug fix? | yes |
New feature? | no |
Tickets | Fix #549 |
License | MIT |
if ($params) { | ||
$queryBuilder | ||
->where(sprintf("o.$idField IN (%s)", implode(', ', array_keys($params)))) | ||
->setParameters(new ArrayCollection($params)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My two cents, using ->setParameters()
will override the previous bound parameters (if any) to the QueryBuilder
.
IMO it would be preferable to use ->setParameter()
for each $params
, to be future-proof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can't be any previous parameters, because the query is constructed 4 lines before :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the moment yes, but we can't predict the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imho they could be added to $params,no? :)
@norkunas Great fix. Would you mind adding a testcase? |
->getResult(); | ||
$queryBuilder = $repository->createQueryBuilder('o'); | ||
|
||
if ($params) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't just check if $data['autocomplete']
is []
and skip this else part?
Btw this can be simplified a lot like $repository->createQueryBuilder('o')->->where(sprintf('o.%s IN (:ids)', $idField)))->setParameter('ids', $data['autocomplete'])->getQuery()->getResult()
, doctrine will handle the rest, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it won't handle the types properly,that's what I've fixed before.
4dec440
to
15a3bf6
Compare
testcase added. |
15a3bf6
to
d581ea7
Compare
Awesome, thank you Tomas! |