-
-
Notifications
You must be signed in to change notification settings - Fork 364
[Autocomplete] Don't add WHERE IN criteria without params #561
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,11 +73,15 @@ public function preSubmit(FormEvent $event) | |
++$idx; | ||
} | ||
|
||
$options['choices'] = $repository->createQueryBuilder('o') | ||
->where(sprintf("o.$idField IN (%s)", implode(', ', array_keys($params)))) | ||
->setParameters(new ArrayCollection($params)) | ||
->getQuery() | ||
->getResult(); | ||
$queryBuilder = $repository->createQueryBuilder('o'); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. My two cents, using IMO it would be preferable to use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Imho they could be added to $params,no? :) |
||
} | ||
|
||
$options['choices'] = $queryBuilder->getQuery()->getResult(); | ||
} else { | ||
$options['choices'] = $repository->createQueryBuilder('o') | ||
->where("o.$idField = :id") | ||
|
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.