Browse files

more fixes related to inheritance mapping, added support for declared…

… mapping
  • Loading branch information...
1 parent 7576630 commit 07ef1db5add441b8ce47cb89d7574f73dfcce9c0 @lsmith77 lsmith77 committed Feb 10, 2012
View
25 lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php
@@ -38,7 +38,6 @@
*/
class ClassMetadata implements ClassMetadataInterface
{
-
const TO_ONE = 5;
const TO_MANY = 10;
const ONE_TO_ONE = 1;
@@ -263,6 +262,11 @@ class ClassMetadata implements ClassMetadataInterface
private $inheritedFields = array();
/**
+ * @var array
+ */
+ private $declaredFields = array();
+
+ /**
* Initializes a new ClassMetadata instance that will hold the object-document mapping
* metadata of the class with the given name.
*
@@ -463,9 +467,14 @@ public function mapId(array $mapping)
$this->validateAndCompleteFieldMapping($mapping, false);
}
- public function setFieldInherited($fieldName)
+ public function setFieldInherited($fieldName, $className)
+ {
+ $this->inheritedFields[$fieldName] = $className;
+ }
+
+ public function setDeclaredInherited($fieldName, $className)
{
- $this->inheritedFields[$fieldName] = true;
+ $this->declaredFields[$fieldName] = $className;
}
public function mapNode(array $mapping)
@@ -815,6 +824,16 @@ public function isInheritedField($fieldName)
}
/**
+ * Checks whether a mapped field is declared previously.
+ *
+ * @return boolean TRUE if the field is declared, FALSE otherwise.
+ */
+ public function isDeclaredField($fieldName)
+ {
+ return isset($this->declaredFields[$fieldName]);
+ }
+
+ /**
* Map a field.
*
* - type - The Doctrine Type of this field.
View
31 lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
@@ -138,51 +138,60 @@ protected function doLoadMetadata($class, $parent, $rootEntityFound)
private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass)
{
foreach ($parentClass->fieldMappings as $fieldName => $mapping) {
- $subClass->setFieldInherited($fieldName);
+ $this->registerParentOnField($subClass, $parentClass, $fieldName);
$subClass->mapField($mapping);
}
foreach ($parentClass->associationsMappings as $fieldName => $mapping) {
- $subClass->setFieldInherited($fieldName);
+ $this->registerParentOnField($subClass, $parentClass, $fieldName);
$subClass->storeAssociationMapping($mapping);
}
foreach ($parentClass->childMappings as $fieldName => $mapping) {
- $subClass->setFieldInherited($fieldName);
+ $this->registerParentOnField($subClass, $parentClass, $fieldName);
$subClass->mapChild($mapping);
}
foreach ($parentClass->childrenMappings as $fieldName => $mapping) {
- $subClass->setFieldInherited($fieldName);
+ $this->registerParentOnField($subClass, $parentClass, $fieldName);
$subClass->mapChildren($mapping);
}
foreach ($parentClass->referrersMappings as $fieldName => $mapping) {
- $subClass->setFieldInherited($fieldName);
+ $this->registerParentOnField($subClass, $parentClass, $fieldName);
$subClass->mapReferrers($mapping);
}
if ($parentClass->node) {
- $subClass->setFieldInherited($parentClass->node);
+ $this->registerParentOnField($subClass, $parentClass, $parentClass->node);
$subClass->mapNode(array('fieldName' => $parentClass->node));
}
if ($parentClass->nodename) {
- $subClass->setFieldInherited($parentClass->nodename);
+ $this->registerParentOnField($subClass, $parentClass, $parentClass->nodename);
$subClass->mapNodename(array('fieldName' => $parentClass->nodename));
}
if ($parentClass->parentMapping) {
- $subClass->setFieldInherited($parentClass->parentMapping);
+ $this->registerParentOnField($subClass, $parentClass, $parentClass->parentMapping);
$subClass->mapParentDocument(array('fieldName' => $parentClass->parentMapping));
}
if ($parentClass->localeMapping) {
- $subClass->setFieldInherited($parentClass->localeMapping);
+ $this->registerParentOnField($subClass, $parentClass, $parentClass->localeMapping);
$subClass->mapLocale(array('fieldName' => $parentClass->localeMapping));
}
if ($parentClass->versionNameField) {
- $subClass->setFieldInherited($parentClass->versionNameField);
+ $this->registerParentOnField($subClass, $parentClass, $parentClass->versionNameField);
$subClass->mapVersionName(array('fieldName' => $parentClass->versionNameField));
}
if ($parentClass->versionCreatedField) {
- $subClass->setFieldInherited($parentClass->versionCreatedField);
+ $this->registerParentOnField($subClass, $parentClass, $parentClass->versionCreatedField);
$subClass->mapVersionCreated(array('fieldName' => $parentClass->versionCreatedField));
}
}
+ private function registerParentOnField(ClassMetadata $subClass, ClassMetadata $parentClass, $fieldName)
+ {
+ if (!$parentClass->isInheritedField($fieldName) && !$parentClass->isMappedSuperclass) {
+ $subClass->setFieldInherited($fieldName, $parentClass->name);
+ }
+ if (!$parentClass->isDeclaredField($fieldName)) {
+ $subClass->setDeclaredInherited($fieldName, $parentClass->name);
+ }
+ }
/**
* {@inheritdoc}
*/

0 comments on commit 07ef1db

Please sign in to comment.