Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix mappedsuperclass (porting fix from #61 by @DavidBadura) #65

Merged
merged 2 commits into from

4 participants

@dbu
dbu commented

@DavidBadura pointed me to his PR #61 for lifecycle callbacks where he fixes the bug about mappedsuperclass. i ported that into a separate commit as the other thing seems to be stuck.

this would solve the issue i mention in doctrine/DoctrineCouchDBBundle#27

@stof

@dbu you should add a test to avoid regressions

@dbu

you are right of course. i found not tests about mappings, so i created a new one.

note #64 , there seem to be some failing tests. the newly added test succeeds on my machine.

@beberlei beberlei merged commit facfac0 into doctrine:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 7, 2013
  1. @dbu
Commits on May 10, 2013
  1. @dbu

    adding tests for mapped superclass

    dbu authored
This page is out of date. Refresh to see the latest.
View
29 lib/Doctrine/ODM/CouchDB/Mapping/ClassMetadataFactory.php
@@ -76,6 +76,8 @@ protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonS
{
/** @var $parent ClassMetaData */
if ($parent) {
+ $this->addAssociationsMapping($class, $parent);
+ $this->addFieldMapping($class, $parent);
$parent->deriveChildMetadata($class->getName());
$class->setParentClasses($nonSuperclassParents);
}
@@ -85,6 +87,33 @@ protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonS
}
}
+ private function addFieldMapping(ClassMetadataInterface $class, ClassMetadataInterface $parent)
+ {
+ foreach ($parent->reflFields as $name => $field) {
+ $class->reflFields[$name] = $field;
+ }
+
+ foreach ($parent->fieldMappings as $name => $field) {
+ $class->fieldMappings[$name] = $field;
+ }
+
+ foreach ($parent->jsonNames as $name => $field) {
+ $class->jsonNames[$name] = $field;
+ }
+ }
+
+ /**
+ *
+ * @param ClassMetadataInterface $class
+ * @param ClassMetadataInterface $parent
+ */
+ private function addAssociationsMapping(ClassMetadataInterface $class, ClassMetadataInterface $parent)
+ {
+ foreach ($parent->associationsMappings as $name => $field) {
+ $class->associationsMappings[$name] = $field;
+ }
+ }
+
/**
* {@inheritdoc}
*/
View
14 tests/Doctrine/Tests/Models/Mapping/BaseArticle.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Doctrine\Tests\Models\Mapping;
+
+/**
+ * @Document
+ */
+class BaseArticle
+{
+ /** @Id */
+ public $id;
+ /** @Field(type="string") */
+ public $topic;
+}
View
14 tests/Doctrine/Tests/Models/Mapping/ExtendingClass.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Doctrine\Tests\Models\Mapping;
+
+/**
+ * Model to test extending another model
+ *
+ * @Document
+ */
+class ExtendingClass extends MappedSuperclass
+{
+ /** @Field(type="string") */
+ public $headline;
+}
View
14 tests/Doctrine/Tests/Models/Mapping/HeadlineArticle.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Doctrine\Tests\Models\Mapping;
+
+/**
+ * Model to test extending another model
+ *
+ * @Document
+ */
+class HeadlineArticle extends BaseArticle
+{
+ /** @Field(type="string") */
+ public $headline;
+}
View
14 tests/Doctrine/Tests/Models/Mapping/MappedSuperclass.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Doctrine\Tests\Models\Mapping;
+
+/**
+ * @MappedSuperclass
+ */
+class MappedSuperclass
+{
+ /** @Id */
+ public $id;
+ /** @Field(type="string") */
+ public $topic;
+}
View
56 tests/Doctrine/Tests/ODM/CouchDB/Functional/Mapping/DocumentInheritTest.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Doctrine\Tests\ODM\CouchDB\Functional\Mapping;
+
+use Doctrine\ODM\CouchDB\DocumentManager;
+use Doctrine\Tests\Models\Mapping\HeadlineArticle;
+use Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase;
+use Doctrine\Tests\Models\Mapping\ExtendingClass;
+
+/**
+ * Test about mapped superclass and about extending a base document
+ */
+class DocumentInheritTest extends CouchDBFunctionalTestCase
+{
+ /** @var DocumentManager */
+ private $dm;
+
+ public function setUp()
+ {
+ $this->dm = $this->createDocumentManager();
+ }
+
+ public function testLoadingParentClass()
+ {
+ $document = new HeadlineArticle();
+ $document->topic = 'Superclass test';
+ $document->headline = 'test test test';
+ $this->dm->persist($document);
+ $this->dm->flush();
+ $id = $document->id;
+
+ $this->dm->clear();
+
+ $doc = $this->dm->find('Doctrine\Tests\Models\Mapping\HeadlineArticle', $id);
+ $this->assertInstanceOf('\Doctrine\Tests\Models\Mapping\HeadlineArticle', $doc);
+ $this->assertEquals('test test test', $doc->headline);
+ $this->assertEquals('Superclass test', $doc->topic);
+ }
+
+ public function testLoadingMappedsuperclass()
+ {
+ $document = new ExtendingClass();
+ $document->topic = 'Superclass test';
+ $document->headline = 'test test test';
+ $this->dm->persist($document);
+ $this->dm->flush();
+ $id = $document->id;
+
+ $this->dm->clear();
+
+ $doc = $this->dm->find('Doctrine\Tests\Models\Mapping\ExtendingClass', $id);
+ $this->assertInstanceOf('\Doctrine\Tests\Models\Mapping\ExtendingClass', $doc);
+ $this->assertEquals('test test test', $doc->headline);
+ $this->assertEquals('Superclass test', $doc->topic);
+ }
+}
Something went wrong with that request. Please try again.