DDC-1697: DQL Query with key=>value array in parameter #2134

Open
opened 2026-01-22 13:42:22 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 12, 2012).

Jira issue originally created by user waldo2188:

In he method "processParameterValue" in the class Doctrine\ORM\Query line 303, a "for" loop is use for construct the parameter query.

But if in the query parameter we pass a key=>value array, the method throw an error.

A little example :
$aId = array(0 => "Paris", 3 => "Canne", 9 => "St Julien");

$dql = $this->_em->createQueryBuilder();
$dql->select('c.ID')
->from('BOD\ModelBundle\Entity\City', 'c')
->where('c.IC IN (:cityIDs)')
->setParameter('cityIDs', $aId);

return $dql->getQuery()->execute();

The method "processParameterValue" throw an error because he don't found the index 1.

But if we replace the "for" loop by a foreach in Doctrine\ORM\Query::processParameterValue() :
foreach ($value as $keyValue => $oneValue) {
$paramValue = $this->processParameterValue($oneValue);

// TODO: What about Entities that have composite primary key?
$value[$keyValue] = is_array($paramValue) ? $paramValue[key($paramValue)] : $paramValue;
}

It work really fine.

I remain at your disposal for any further information.

Thanks for all!

Originally created by @doctrinebot on GitHub (Mar 12, 2012). Jira issue originally created by user waldo2188: In he method "processParameterValue" in the class Doctrine\ORM\Query line 303, a "for" loop is use for construct the parameter query. But if in the query parameter we pass a key=>value array, the method throw an error. A little example : $aId = array(0 => "Paris", 3 => "Canne", 9 => "St Julien"); $dql = $this->_em->createQueryBuilder(); $dql->select('c.ID') ->from('BOD\ModelBundle\Entity\City', 'c') ->where('c.IC IN (:cityIDs)') ->setParameter('cityIDs', $aId); return $dql->getQuery()->execute(); The method "processParameterValue" throw an error because he don't found the index 1. But if we replace the "for" loop by a foreach in Doctrine\ORM\Query::processParameterValue() : foreach ($value as $keyValue => $oneValue) { $paramValue = $this->processParameterValue($oneValue); // TODO: What about Entities that have composite primary key? $value[$keyValue] = is_array($paramValue) ? $paramValue[key($paramValue)] : $paramValue; } It work really fine. I remain at your disposal for any further information. Thanks for all!
admin added the Improvement label 2026-01-22 13:42:22 +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#2134