Skip to content

Commit

Permalink
[DDC-388] Fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
romanb committed Apr 14, 2010
1 parent 7fefe3f commit d4232d9
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 191 deletions.
7 changes: 1 addition & 6 deletions lib/Doctrine/ORM/AbstractQuery.php
Expand Up @@ -410,12 +410,7 @@ public function getSingleResult($hydrationMode = null)
throw new NonUniqueResultException;
}
return array_shift($result);
}/* else if (is_object($result)) {
if (count($result) > 1) {
throw new NonUniqueResultException;
}
return $result->first();
}*/
}

return $result;
}
Expand Down
29 changes: 21 additions & 8 deletions lib/Doctrine/ORM/Mapping/AssociationMapping.php
@@ -1,7 +1,5 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Expand Down Expand Up @@ -152,7 +150,23 @@ abstract class AssociationMapping
*
* @var array
*/
public $joinTable = array();
public $joinTable;

/**
* READ-ONLY: The name of the entity class from which the association was
* inherited in an inheritance hierarchy.
*
* @var string
*/
public $inherited;

/**
* READ-ONLY: The name of the entity or mapped superclass that declares
* the association field in an inheritance hierarchy.
*
* @var string
*/
public $declared;

/**
* Initializes a new instance of a class derived from AssociationMapping.
Expand All @@ -161,9 +175,7 @@ abstract class AssociationMapping
*/
public function __construct(array $mapping)
{
if ($mapping) {
$this->_validateAndCompleteMapping($mapping);
}
$this->_validateAndCompleteMapping($mapping);
}

/**
Expand Down Expand Up @@ -317,8 +329,9 @@ public function hasCascades()
abstract public function load($sourceEntity, $target, $em, array $joinColumnValues = array());

/**
*
* @param $platform
* Gets the (possibly quoted) name of the join table.
*
* @param AbstractPlatform $platform
* @return string
*/
public function getQuotedJoinTableName($platform)
Expand Down
44 changes: 8 additions & 36 deletions lib/Doctrine/ORM/Mapping/ClassMetadata.php
@@ -1,7 +1,5 @@
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Expand Down Expand Up @@ -72,11 +70,10 @@ class ClassMetadata extends ClassMetadataInfo
*/
public function __construct($entityName)
{
$this->name = $entityName;
$this->reflClass = new \ReflectionClass($entityName);
parent::__construct($entityName);
$this->reflClass = new ReflectionClass($entityName);
$this->namespace = $this->reflClass->getNamespaceName();
$this->table['name'] = $this->reflClass->getShortName();
$this->rootEntityName = $entityName;
}

/**
Expand All @@ -99,18 +96,6 @@ public function getReflectionProperties()
return $this->reflFields;
}

/**
* INTERNAL:
* Adds a reflection property. Usually only used by the ClassMetadataFactory
* while processing inheritance mappings.
*
* @param array $props
*/
public function addReflectionProperty($propName, \ReflectionProperty $property)
{
$this->reflFields[$propName] = $property;
}

/**
* Gets a ReflectionProperty for a specific field of the mapped class.
*
Expand Down Expand Up @@ -189,7 +174,7 @@ public function getIdentifierValues($entity)
public function setIdentifierValues($entity, $id)
{
if ($this->isIdentifierComposite) {
foreach ((array)$id as $idField => $idValue) {
foreach ($id as $idField => $idValue) {
$this->reflFields[$idField]->setValue($entity, $idValue);
}
} else {
Expand Down Expand Up @@ -220,18 +205,6 @@ public function getFieldValue($entity, $field)
return $this->reflFields[$field]->getValue($entity);
}

/**
* Sets the field mapped to the specified column to the specified value on the given entity.
*
* @param object $entity
* @param string $field
* @param mixed $value
*/
public function setColumnValue($entity, $column, $value)
{
$this->reflFields[$this->fieldNames[$column]]->setValue($entity, $value);
}

/**
* Stores the association mapping.
*
Expand Down Expand Up @@ -314,7 +287,6 @@ public function __sleep()
'identifier',
'idGenerator', //TODO: Does not really need to be serialized. Could be moved to runtime.
'inheritanceType',
'inheritedAssociationFields',
'isIdentifierComposite',
'isMappedSuperclass',
'isVersioned',
Expand All @@ -337,10 +309,10 @@ public function __wakeup()
{
// Restore ReflectionClass and properties
$this->reflClass = new ReflectionClass($this->name);

foreach ($this->fieldMappings as $field => $mapping) {
if (isset($mapping['inherited'])) {
$reflField = new ReflectionProperty($mapping['inherited'], $field);
if (isset($mapping['declared'])) {
$reflField = new ReflectionProperty($mapping['declared'], $field);
} else {
$reflField = $this->reflClass->getProperty($field);
}
Expand All @@ -349,8 +321,8 @@ public function __wakeup()
}

foreach ($this->associationMappings as $field => $mapping) {
if (isset($this->inheritedAssociationFields[$field])) {
$reflField = new ReflectionProperty($this->inheritedAssociationFields[$field], $field);
if ($mapping->declared) {
$reflField = new ReflectionProperty($mapping->declared, $field);
} else {
$reflField = $this->reflClass->getProperty($field);
}
Expand Down
26 changes: 14 additions & 12 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Expand Up @@ -317,31 +317,33 @@ private function _addInheritedFields(ClassMetadata $subClass, ClassMetadata $par
if ( ! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) {
$mapping['inherited'] = $parentClass->name;
}
$subClass->addFieldMapping($mapping);
if ( ! isset($mapping['declared'])) {
$mapping['declared'] = $parentClass->name;
}
$subClass->addInheritedFieldMapping($mapping);
}
foreach ($parentClass->reflFields as $name => $field) {
$subClass->reflFields[$name] = $field;
}
}

/**
* Adds inherited associations to the subclass mapping.
* Adds inherited association mappings to the subclass mapping.
*
* @param Doctrine\ORM\Mapping\ClassMetadata $subClass
* @param Doctrine\ORM\Mapping\ClassMetadata $parentClass
*/
private function _addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass)
{
foreach ($parentClass->associationMappings as $mapping) {
if (isset($parentClass->inheritedAssociationFields[$mapping->sourceFieldName])) {
// parent class also inherited that one
$subClass->addAssociationMapping($mapping, $parentClass->inheritedAssociationFields[$mapping->sourceFieldName]);
} else if ( ! $parentClass->isMappedSuperclass) {
// parent class defined that one
$subClass->addAssociationMapping($mapping, $parentClass->name);
} else {
$subClass->addAssociationMapping($mapping);
foreach ($parentClass->associationMappings as $field => $mapping) {
$subclassMapping = clone $mapping;
if ( ! isset($mapping->inherited) && ! $parentClass->isMappedSuperclass) {
$subclassMapping->inherited = $parentClass->name;
}
if ( ! isset($mapping->declared)) {
$subclassMapping->declared = $parentClass->name;
}
$subClass->addInheritedAssociationMapping($subclassMapping);
}
}

Expand Down

0 comments on commit d4232d9

Please sign in to comment.