Skip to content

Commit

Permalink
Adde more BC compatibility in setParameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermeblanco committed May 29, 2012
1 parent b3e7493 commit 161ae31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/Doctrine/ORM/AbstractQuery.php
Expand Up @@ -186,8 +186,17 @@ function ($parameter) use ($key)
*/
public function setParameters($parameters)
{
// BC compatibility with 2.3-
if (is_array($parameters)) {
$parameters = new ArrayCollection($parameters);
$parameterCollection = new ArrayCollection();

foreach ($parameters as $key => $value) {
$parameter = new Query\Parameter($key, $value);

$parameterCollection->add($parameter);
}

$parameters = $parameterCollection;
}

$this->parameters = $parameters;
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/QueryTest.php
Expand Up @@ -165,6 +165,14 @@ public function testSetParameters()
$users = $q->getResult();
}

public function testSetParametersBackwardsCompatible()
{
$q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1 AND u.status = ?2');
$q->setParameters(array(1 => 'jwage', 2 => 'active'));

$users = $q->getResult();
}

/**
* @group DDC-1070
*/
Expand Down

0 comments on commit 161ae31

Please sign in to comment.