[PR #8375] Support for Array parameters in SQL filters #10953

Closed
opened 2026-01-22 16:09:12 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/8375

State: closed
Merged: Yes


Supersedes https://github.com/doctrine/orm/pull/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):

class CMSCountryFilter extends SQLFilter
{
    public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
    {
        if ($targetEntity->name !== CmsAddress::class || !$this->hasParameter('country')) {
            return "";
        }

        return $targetTableAlias.'.country IN (' . $this->getParameterList('country') . ')';
    }
}

To use getParameterList you must also pass the values using the new setParameterList method. It does not support type inference as we don't need to inspect the array elements then (which could be different).

$em->getFilters()->getFilter('country')->setParameter('country', ['de', 'es']);

Passing a list/single value and retrieving a single/list value (mixed up) will throw a new FilterException.

**Original Pull Request:** https://github.com/doctrine/orm/pull/8375 **State:** closed **Merged:** Yes --- Supersedes https://github.com/doctrine/orm/pull/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)`: ```php class CMSCountryFilter extends SQLFilter { public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if ($targetEntity->name !== CmsAddress::class || !$this->hasParameter('country')) { return ""; } return $targetTableAlias.'.country IN (' . $this->getParameterList('country') . ')'; } } ``` To use `getParameterList` you must also pass the values using the new `setParameterList` method. It does not support type inference as we don't need to inspect the array elements then (which could be different). ```php $em->getFilters()->getFilter('country')->setParameter('country', ['de', 'es']); ``` Passing a list/single value and retrieving a single/list value (mixed up) will throw a new `FilterException`.
admin added the pull-request label 2026-01-22 16:09:12 +01:00
admin closed this issue 2026-01-22 16:09:12 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#10953