Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38fdda6

Browse files
Mihai Stancufabpot
Mihai Stancu
authored andcommitted
Embedded identifier support
1 parent f24690e commit 38fdda6

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function getEntitiesByIds($identifier, array $values)
7979
$qb = clone $this->queryBuilder;
8080
$alias = current($qb->getRootAliases());
8181
$parameter = 'ORMQueryBuilderLoader_getEntitiesByIds_'.$identifier;
82+
$parameter = str_replace('.', '_', $parameter);
8283
$where = $qb->expr()->in($alias.'.'.$identifier, ':'.$parameter);
8384

8485
// Guess type
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures\Embeddable;
13+
14+
use Doctrine\ORM\Mapping as ORM;
15+
16+
/**
17+
* @ORM\Embeddable
18+
*/
19+
class Identifier
20+
{
21+
/**
22+
* @var int
23+
*
24+
* @ORM\Id
25+
* @ORM\Column(type="integer")
26+
*/
27+
protected $value;
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\Mapping as ORM;
15+
16+
/**
17+
* @ORM\Entity
18+
*/
19+
class EmbeddedIdentifierEntity
20+
{
21+
/**
22+
* @var Embeddable\Identifier
23+
*
24+
* @ORM\Embedded(class="Symfony\Bridge\Doctrine\Tests\Fixtures\Embeddable\Identifier")
25+
*/
26+
protected $id;
27+
}

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
1515
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
1616
use Doctrine\DBAL\Connection;
17+
use Doctrine\ORM\Version;
1718

1819
class ORMQueryBuilderLoaderTest extends \PHPUnit_Framework_TestCase
1920
{
@@ -103,4 +104,38 @@ public function testFilterNonIntegerValues()
103104
$loader = new ORMQueryBuilderLoader($qb);
104105
$loader->getEntitiesByIds('id', array(1, '', 2, 3, 'foo'));
105106
}
107+
108+
public function testEmbeddedIdentifierName()
109+
{
110+
if (Version::compare('2.5.0') > 0) {
111+
$this->markTestSkipped('Applicable only for Doctrine >= 2.5.0');
112+
113+
return;
114+
}
115+
116+
$em = DoctrineTestHelper::createTestEntityManager();
117+
118+
$query = $this->getMockBuilder('QueryMock')
119+
->setMethods(array('setParameter', 'getResult', 'getSql', '_doExecute'))
120+
->getMock();
121+
122+
$query->expects($this->once())
123+
->method('setParameter')
124+
->with('ORMQueryBuilderLoader_getEntitiesByIds_id_value', array(1, 2, 3), Connection::PARAM_INT_ARRAY)
125+
->willReturn($query);
126+
127+
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
128+
->setConstructorArgs(array($em))
129+
->setMethods(array('getQuery'))
130+
->getMock();
131+
$qb->expects($this->once())
132+
->method('getQuery')
133+
->willReturn($query);
134+
135+
$qb->select('e')
136+
->from('Symfony\Bridge\Doctrine\Tests\Fixtures\EmbeddedIdentifierEntity', 'e');
137+
138+
$loader = new ORMQueryBuilderLoader($qb);
139+
$loader->getEntitiesByIds('id.value', array(1, '', 2, 3, 'foo'));
140+
}
106141
}

0 commit comments

Comments
 (0)