[PR #590] [MERGED] DQL Query: process ArrayCollection values to ease development #8412

Open
opened 2026-01-22 15:59:49 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/590
Author: @michaelperrin
Created: 2/25/2013
Status: Merged
Merged: 12/17/2013
Merged by: @guilhermeblanco

Base: masterHead: feature/process-collection-value


📝 Commits (1)

  • 1032a16 Simpler way to handle Collection parameters in DQL queries (refs #DDC-2319)

📊 Changes

2 files changed (+55 additions, -1 deletions)

View changed files

📝 lib/Doctrine/ORM/AbstractQuery.php (+6 -1)
📝 tests/Doctrine/Tests/ORM/Functional/QueryTest.php (+49 -0)

📄 Description

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 solves that.

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

This enhancement is now unit-tested in this same PR.

So far, the only solution was to do the following, which is pretty borring:

$categoryIds = array();

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

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/590 **Author:** [@michaelperrin](https://github.com/michaelperrin) **Created:** 2/25/2013 **Status:** ✅ Merged **Merged:** 12/17/2013 **Merged by:** [@guilhermeblanco](https://github.com/guilhermeblanco) **Base:** `master` ← **Head:** `feature/process-collection-value` --- ### 📝 Commits (1) - [`1032a16`](https://github.com/doctrine/orm/commit/1032a16db29f1e6a68b9b1a8faa866984fa8045f) Simpler way to handle Collection parameters in DQL queries (refs #DDC-2319) ### 📊 Changes **2 files changed** (+55 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `lib/Doctrine/ORM/AbstractQuery.php` (+6 -1) 📝 `tests/Doctrine/Tests/ORM/Functional/QueryTest.php` (+49 -0) </details> ### 📄 Description 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 solves that. ~~Note that I didn't add any unit test for this feature. Can you explain me where I should add the test?~~ **This enhancement is now unit-tested in this same PR.** So far, the only solution was to do the following, which is pretty borring: ``` php $categoryIds = array(); foreach ($categories as $category) { $categoryIds[] = $category->getId(); } $queryBuilder = $this ->where('model.category IN (:category_ids)') ->setParameter('category_ids', $categoryIds) ; ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 15:59:49 +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#8412