-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Support for Array parameters in SQL filters #8375
Conversation
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.
Please also cover the two exception cases in getParameterList()
.
} | ||
|
||
$param = $this->parameters[$name]; | ||
$isTraversable = is_array($param['value']); // WARNING: no Traversable support, because it might break on hashing |
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.
// WARNING: no Traversable support
Still, the variable is named $isTraversable
:-D.
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.
Removed traversable support explicitly now.
@@ -401,7 +431,7 @@ public function testQueryGenerationDependsOnFilters(): void | |||
$conf = $this->_em->getConfiguration(); | |||
$conf->addFilter('country', '\Doctrine\Tests\ORM\Functional\CMSCountryFilter'); | |||
$this->_em->getFilters()->enable('country') | |||
->setParameter('country', 'en', DBALType::STRING); | |||
->setParameter('country', ['en'], DBALType::STRING); |
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 changing an existing test and filter?
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.
Because we have two filters in the test, one for locale one for country. By changing one to be a list we maximize test coverage without adding more tests.
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.
After the typos that @greg0ire mentioned are fixed, this is 👍
Co-authored-by: Grégoire Paris <[email protected]>
Supersedes #5571 by @mnogales
Fixes #2624
The original PR had a conceptual problem by putting the array detection directly into
getParameter()
, but this could be a BC break for array DBAL types and it could be a risk, because the generated SQL must be written by the filter implementor, so magically returning a quoted list instead a quoted value could break things.Instead you must combine your generated SQL IN query with
$this->getParameterList($name)
:To use
getParameterList
you must also pass the values using the newsetParameterList
method. It does not support type inference as we don't need to inspect the array elements then (which could be different).Passing a list/single value and retrieving a single/list value (mixed up) will throw a new
FilterException
.