Browse files

Merge pull request #793 from doctrine/mapped-superclass-custom-reposi…

…tory

Support repositoryClass on MappedSuperclass
  • Loading branch information...
2 parents 382f844 + 72717c7 commit 9d16a70854627dac71c561e10a7bee2b32023de0 @jmikola jmikola committed Feb 4, 2014
View
4 lib/Doctrine/ODM/MongoDB/Mapping/Annotations/MappedSuperclass.php
@@ -22,4 +22,8 @@
/** @Annotation */
final class MappedSuperclass extends AbstractDocument
{
+ /**
+ * @var string
+ */
+ public $repositoryClass;
}
View
3 lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
@@ -59,6 +59,9 @@ public function loadMetadataForClass($className, ClassMetadata $class)
$class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
}
} elseif ($xmlRoot->getName() == 'mapped-superclass') {
+ $class->setCustomRepositoryClass(
+ isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null
+ );
$class->isMappedSuperclass = true;
} elseif ($xmlRoot->getName() == 'embedded-document') {
$class->isEmbeddedDocument = true;
View
3 lib/Doctrine/ODM/MongoDB/Mapping/Driver/YamlDriver.php
@@ -66,6 +66,9 @@ public function loadMetadataForClass($className, ClassMetadata $class)
$class->setCustomRepositoryClass($element['repositoryClass']);
}
} elseif ($element['type'] === 'mappedSuperclass') {
+ $class->setCustomRepositoryClass(
+ isset($element['repositoryClass']) ? $element['repositoryClass'] : null
+ );
$class->isMappedSuperclass = true;
} elseif ($element['type'] === 'embeddedDocument') {
$class->isEmbeddedDocument = true;
View
10 tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php
@@ -15,6 +15,16 @@ public function testCustomRepository()
$this->assertInstanceOf('Documents\CustomRepository\Repository', $this->dm->getRepository('Documents\CustomRepository\Document'));
}
+ public function testCustomRepositoryMappedsuperclass()
+ {
+ $this->assertInstanceOf('Documents\BaseCategoryRepository', $this->dm->getRepository('Documents\BaseCategory'));
+ }
+
+ public function testCustomRepositoryMappedsuperclassChild()
+ {
+ $this->assertInstanceOf('Documents\BaseCategoryRepository', $this->dm->getRepository('Documents\Category'));
+ }
+
public function testGetConnection()
{
$this->assertInstanceOf('\Doctrine\MongoDB\Connection', $this->dm->getConnection());
View
2 tests/Documents/BaseCategory.php
@@ -4,7 +4,7 @@
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
-/** @ODM\MappedSuperclass */
+/** @ODM\MappedSuperclass(repositoryClass="Documents\BaseCategoryRepository") */
abstract class BaseCategory
{
/** @ODM\String */
View
7 tests/Documents/BaseCategoryRepository.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace Documents;
+
+use Doctrine\ODM\MongoDB\DocumentRepository;
+
+class BaseCategoryRepository extends DocumentRepository {}

0 comments on commit 9d16a70

Please sign in to comment.