[DDC-2319] [GH-590] DQL Query: process ArrayCollection values to ease development Created: 25/Feb/13  Updated: 31/Jul/14  Resolved: 17/Dec/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: 2.5
Security Level: All

Type: Improvement Priority: Major
Reporter: Benjamin Eberlei Assignee: Guilherme Blanco
Resolution: Fixed Votes: 0
Labels: None


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

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


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?


Comment by Doctrine Bot [ 17/Dec/13 ]

A related Github Pull-Request [GH-590] was closed:

Comment by Marco Pivetta [ 17/Dec/13 ]

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

Comment by Doctrine Bot [ 30/Apr/14 ]

A related Github Pull-Request [GH-590] was closed:

Comment by Doctrine Bot [ 31/Jul/14 ]

A related Github Pull-Request [GH-590] was closed:

Generated at Wed Apr 01 03:26:08 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.