From 6fc18e330d8ecd57dc9a4af871d6cc30cffd3f7d Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Tue, 2 Apr 2013 10:04:15 +0200 Subject: [PATCH 1/5] indexby metadata column --- lib/Doctrine/ORM/Query/ResultSetMapping.php | 2 +- .../Tests/ORM/Hydration/ResultSetMappingTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index 50dacea41..b06b68385 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -211,7 +211,7 @@ class ResultSetMapping { $found = false; - foreach ($this->fieldMappings as $columnName => $columnFieldName) { + foreach (array_merge($this->metaMappings, $this->fieldMappings) as $columnName => $columnFieldName) { if ( ! ($columnFieldName === $fieldName && $this->columnOwnerMap[$columnName] === $alias)) continue; $this->addIndexByColumn($alias, $columnName); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index 801937f2d..5a198a944 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -255,5 +255,18 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('status')); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('username')); } + public function testIndexByMetadataColumn() + { + $rms = $this->_rsm; + $rms->addEntityResult('Doctrine\Tests\Models\Legacy\LegacyUser', 'u') + ->addJoinedEntityResult('Doctrine\Tests\Models\Legacy', 'lu', 'u', '_references') + ->addMetaResult('lu', '_source', '_source', true) + ->addMetaResult('lu', '_target', '_target', true) + ->addIndexBy('lu', '_source'); + + + $this->assertTrue($rms->hasIndexBy('lu')); + + } } From 3196b0c05a9cd4507463a82b706f691f686a8224 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Tue, 2 Apr 2013 10:14:24 +0200 Subject: [PATCH 2/5] missing new line --- tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index 5a198a944..fac93b6e6 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -255,6 +255,7 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('status')); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('username')); } + public function testIndexByMetadataColumn() { $rms = $this->_rsm; From 34adb16ee85deb0e26caab0eeeecbcf7ae7752de Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Mon, 29 Apr 2013 10:29:58 +0200 Subject: [PATCH 3/5] indexby ddc117 tests --- .../Tests/Models/DDC117/DDC117Article.php | 10 +++++++--- .../ORM/Functional/Ticket/DDC117Test.php | 15 +++++++++++++++ .../ORM/Hydration/ResultSetMappingTest.php | 19 +++++++++---------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php b/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php index d77bb942b..655ac3611 100644 --- a/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php +++ b/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php @@ -24,12 +24,12 @@ class DDC117Article private $details; /** - * @OneToMany(targetEntity="DDC117Translation", mappedBy="article", cascade={"persist", "remove"}) + * @OneToMany(targetEntity="DDC117Translation", mappedBy="article", indexBy="language", cascade={"persist", "remove"}) */ private $translations; /** - * @OneToMany(targetEntity="DDC117Link", mappedBy="source") + * @OneToMany(targetEntity="DDC117Link", mappedBy="source", indexBy="target_id") */ private $links; @@ -75,6 +75,10 @@ class DDC117Article return $this->details; } + public function getLinks() + { + return $this->links; + } public function resetText() { $this->details = null; @@ -84,4 +88,4 @@ class DDC117Article { return $this->translations; } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php index 34e329465..6673afd1a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php @@ -8,6 +8,7 @@ use Doctrine\Tests\Models\DDC117\DDC117Reference; use Doctrine\Tests\Models\DDC117\DDC117Translation; use Doctrine\Tests\Models\DDC117\DDC117ApproveChanges; use Doctrine\Tests\Models\DDC117\DDC117Editor; +use Doctrine\Tests\Models\DDC117\DDC117Link; require_once __DIR__ . '/../../../TestInit.php'; @@ -30,6 +31,9 @@ class DDC117Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($this->article2); $this->_em->flush(); + $link = new DDC117Link($this->article1, $this->article2, "Link-Description"); + $this->_em->persist($link); + $this->reference = new DDC117Reference($this->article1, $this->article2, "Test-Description"); $this->_em->persist($this->reference); @@ -479,4 +483,15 @@ class DDC117Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($reference)); } + /** + * @group DDC-117 + */ + public function testIndexByOnCompositeKeyField() + { + $article = $this->_em->find("Doctrine\Tests\Models\DDC117\DDC117Article", $this->article1->id()); + + $this->assertInstanceOf('Doctrine\Tests\Models\DDC117\DDC117Article', $article); + $this->assertEquals(1, count($article->getLinks())); + $this->assertTrue($article->getLinks()->offsetExists($this->article2->id())); + } } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index fac93b6e6..700e3fe05 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -255,19 +255,18 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('status')); $this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $rsm->getDeclaringClass('username')); } - + /** + * @group DDC-117 + */ public function testIndexByMetadataColumn() { - $rms = $this->_rsm; - $rms->addEntityResult('Doctrine\Tests\Models\Legacy\LegacyUser', 'u') - ->addJoinedEntityResult('Doctrine\Tests\Models\Legacy', 'lu', 'u', '_references') - ->addMetaResult('lu', '_source', '_source', true) - ->addMetaResult('lu', '_target', '_target', true) - ->addIndexBy('lu', '_source'); - - - $this->assertTrue($rms->hasIndexBy('lu')); + $this->_rsm->addEntityResult('Doctrine\Tests\Models\Legacy\LegacyUser', 'u'); + $this->_rsm->addJoinedEntityResult('Doctrine\Tests\Models\Legacy', 'lu', 'u', '_references'); + $this->_rsm->addMetaResult('lu', '_source', '_source', true); + $this->_rsm->addMetaResult('lu', '_target', '_target', true); + $this->_rsm->addIndexBy('lu', '_source'); + $this->assertTrue($this->_rsm->hasIndexBy('lu')); } } From 2ca24375e417855b8f4adbc4a885c2b3e8424116 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Mon, 29 Apr 2013 10:32:40 +0200 Subject: [PATCH 4/5] no lang --- tests/Doctrine/Tests/Models/DDC117/DDC117Article.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php b/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php index 655ac3611..e1df91c9a 100644 --- a/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php +++ b/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php @@ -24,7 +24,7 @@ class DDC117Article private $details; /** - * @OneToMany(targetEntity="DDC117Translation", mappedBy="article", indexBy="language", cascade={"persist", "remove"}) + * @OneToMany(targetEntity="DDC117Translation", mappedBy="article", cascade={"persist", "remove"}) */ private $translations; From 7abf46af7038559b83d0d3f963685ca04a2fbe17 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Mon, 29 Apr 2013 11:03:55 +0200 Subject: [PATCH 5/5] cascade remove persist on links --- tests/Doctrine/Tests/Models/DDC117/DDC117Article.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php b/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php index e1df91c9a..9d57b5652 100644 --- a/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php +++ b/tests/Doctrine/Tests/Models/DDC117/DDC117Article.php @@ -29,7 +29,7 @@ class DDC117Article private $translations; /** - * @OneToMany(targetEntity="DDC117Link", mappedBy="source", indexBy="target_id") + * @OneToMany(targetEntity="DDC117Link", mappedBy="source", indexBy="target_id", cascade={"persist", "remove"}) */ private $links;