Skip to content

Commit

Permalink
more fixes related to inheritance mapping, added support for declared…
Browse files Browse the repository at this point in the history
… mapping
  • Loading branch information
lsmith77 committed Feb 10, 2012
1 parent 7576630 commit 07ef1db
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
25 changes: 22 additions & 3 deletions lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php
Expand Up @@ -38,7 +38,6 @@
*/
class ClassMetadata implements ClassMetadataInterface
{

const TO_ONE = 5;
const TO_MANY = 10;
const ONE_TO_ONE = 1;
Expand Down Expand Up @@ -262,6 +261,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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -814,6 +823,16 @@ public function isInheritedField($fieldName)
return isset($this->inheritedFields[$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.
*
Expand Down
31 changes: 20 additions & 11 deletions lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
Expand Up @@ -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}
*/
Expand Down

0 comments on commit 07ef1db

Please sign in to comment.