DDC-2319: [GH-590] DQL Query: process ArrayCollection values to ease development #2912

Closed
opened 2026-01-22 14:07:12 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 25, 2013).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user @beberlei:

This issue is created automatically through a Github pull request on behalf of michaelperrin:

Url: https://github.com/doctrine/doctrine2/pull/590

Message:

I added some code to ease "where in" parameter binding.

As you know, when a where condition is added, the object itself can be passed as a parameter and it's id is automatically retrieved:

$queryBuilder = $this
    ->where('model.category = :category')
    ->setParameter('category', $category)
;

Where $category is an object.

But it doesn't work for collections:

$queryBuilder = $this
    ->where('model.category IN (:categories)')
    ->setParameter('categories', $categories)
;

Where categories is an ArrayCollection object (retrieved from a many to one relation for instance).

This doesn't work in the current version of Doctrine, and my PR solved that.

So far, the only solution is to do the following:

$categoryIds = array();

foreach ($categories as $category) {
    $categoryIds[] = $category->getId();
}

$queryBuilder = $this
    ->where('model.category IN (:category_ids)')
    ->setParameter('category_ids', $categoryIds)
;

And this is pretty borring when you have to do it several times for several entities.

Note that I didn't add any unit test for this feature. Can you explain me where I should add the test?

Thanks!

Originally created by @doctrinebot on GitHub (Feb 25, 2013). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user @beberlei: This issue is created automatically through a Github pull request on behalf of michaelperrin: Url: https://github.com/doctrine/doctrine2/pull/590 Message: I added some code to ease "where in" parameter binding. As you know, when a where condition is added, the object itself can be passed as a parameter and it's id is automatically retrieved: ``` php $queryBuilder = $this ->where('model.category = :category') ->setParameter('category', $category) ; ``` Where `$category` is an object. But it doesn't work for collections: ``` php $queryBuilder = $this ->where('model.category IN (:categories)') ->setParameter('categories', $categories) ; ``` Where categories is an `ArrayCollection` object (retrieved from a many to one relation for instance). This doesn't work in the current version of Doctrine, and my PR solved that. So far, the only solution is to do the following: ``` php $categoryIds = array(); foreach ($categories as $category) { $categoryIds[] = $category->getId(); } $queryBuilder = $this ->where('model.category IN (:category_ids)') ->setParameter('category_ids', $categoryIds) ; ``` And this is pretty borring when you have to do it several times for several entities. Note that I didn't add any unit test for this feature. Can you explain me where I should add the test? Thanks!
admin added the Improvement label 2026-01-22 14:07:12 +01:00
admin closed this issue 2026-01-22 14:07:12 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 17, 2013):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-590] was closed:
https://github.com/doctrine/doctrine2/pull/590

@doctrinebot commented on GitHub (Dec 17, 2013): Comment created by @doctrinebot: A related Github Pull-Request [GH-590] was closed: https://github.com/doctrine/doctrine2/pull/590
Author
Owner

@doctrinebot commented on GitHub (Dec 17, 2013):

Comment created by @ocramius:

Merged: https://github.com/doctrine/doctrine2/commit/423ea00539d11e9a12e952a7e9144bd2c53019dc

@doctrinebot commented on GitHub (Dec 17, 2013): Comment created by @ocramius: Merged: https://github.com/doctrine/doctrine2/commit/423ea00539d11e9a12e952a7e9144bd2c53019dc
Author
Owner

@doctrinebot commented on GitHub (Dec 17, 2013):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Dec 17, 2013): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Apr 30, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-590] was closed:
https://github.com/doctrine/dbal/pull/590

@doctrinebot commented on GitHub (Apr 30, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-590] was closed: https://github.com/doctrine/dbal/pull/590
Author
Owner

@doctrinebot commented on GitHub (Jul 31, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-590] was closed:
https://github.com/doctrine/dbal/pull/590

@doctrinebot commented on GitHub (Jul 31, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-590] was closed: https://github.com/doctrine/dbal/pull/590
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2912