From 7cc56c45d334f6e9d2c21de3c8e90d8734d26285 Mon Sep 17 00:00:00 2001 From: "Roman S. Borschel" Date: Sat, 10 Apr 2010 00:00:36 +0200 Subject: [PATCH] [DDC-193] Fixed. --- UPGRADE_TO_2_0 | 2 +- doctrine-mapping.xsd | 9 ++- lib/Doctrine/Common/EventArgs.php | 2 +- lib/Doctrine/Common/EventSubscriber.php | 7 +-- .../ORM/Internal/Hydration/ObjectHydrator.php | 9 +-- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 1 - .../ORM/Mapping/ClassMetadataInfo.php | 58 +------------------ .../ORM/Mapping/Driver/AbstractFileDriver.php | 12 ++-- .../ORM/Mapping/Driver/AnnotationDriver.php | 4 +- .../ORM/Mapping/Driver/DatabaseDriver.php | 4 +- .../Mapping/Driver/DoctrineAnnotations.php | 2 - .../ORM/Mapping/Driver/DriverChain.php | 6 +- lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php | 1 - lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 29 +++++++--- .../ORM/Mapping/Driver/YamlDriver.php | 14 ++++- .../ORM/Mapping/ManyToManyMapping.php | 12 ++-- lib/Doctrine/ORM/Mapping/OneToOneMapping.php | 14 ++--- lib/Doctrine/ORM/PersistentCollection.php | 17 +----- .../AbstractCollectionPersister.php | 2 +- .../Persisters/StandardEntityPersister.php | 4 +- lib/Doctrine/ORM/UnitOfWork.php | 8 +-- .../Doctrine/Tests/Models/CMS/CmsAddress.php | 12 ++-- .../Doctrine/Tests/Models/CMS/CmsArticle.php | 2 +- .../Doctrine/Tests/Models/CMS/CmsComment.php | 2 +- .../Doctrine/Tests/Models/CMS/CmsEmployee.php | 4 +- tests/Doctrine/Tests/Models/CMS/CmsGroup.php | 4 +- .../Tests/Models/CMS/CmsPhonenumber.php | 4 +- tests/Doctrine/Tests/Models/CMS/CmsUser.php | 2 +- .../Tests/Models/Company/CompanyEvent.php | 4 +- .../Tests/Models/Company/CompanyPerson.php | 4 +- .../Tests/Models/Company/CompanyRaffle.php | 2 +- .../Tests/Models/ECommerce/ECommerceCart.php | 6 +- .../Models/ECommerce/ECommerceCategory.php | 2 +- .../Models/ECommerce/ECommerceFeature.php | 6 +- .../Models/ECommerce/ECommerceProduct.php | 10 ++-- .../Models/ECommerce/ECommerceShipping.php | 2 +- .../Tests/Models/Forum/ForumBoard.php | 2 +- .../Doctrine/Tests/Models/Forum/ForumUser.php | 3 +- .../Tests/Models/Generic/DateTimeModel.php | 2 +- .../Tests/Models/Routing/RoutingLeg.php | 7 +-- .../Tests/Models/Routing/RoutingLocation.php | 3 +- .../Tests/Models/Routing/RoutingRoute.php | 2 +- .../Models/Routing/RoutingRouteBooking.php | 4 +- .../ORM/Functional/Ticket/DDC144Test.php | 8 +-- .../ORM/Functional/Ticket/DDC199Test.php | 8 +-- .../ORM/Functional/Ticket/DDC211Test.php | 2 +- .../ORM/Functional/Ticket/DDC237Test.php | 6 +- .../ORM/Functional/Ticket/DDC279Test.php | 8 +-- .../ORM/Functional/Ticket/DDC309Test.php | 4 +- .../ORM/Functional/Ticket/DDC345Test.php | 4 +- .../ORM/Functional/Ticket/DDC353Test.php | 3 +- .../ORM/Functional/Ticket/DDC371Test.php | 2 +- .../ORM/Functional/Ticket/DDC381Test.php | 2 +- .../Tests/ORM/Functional/Ticket/Ticket69.php | 4 +- .../ORM/Mapping/AbstractMappingDriverTest.php | 5 +- .../Tests/ORM/Mapping/ClassMetadataTest.php | 4 +- .../php/Doctrine.Tests.ORM.Mapping.User.php | 1 + .../Doctrine.Tests.ORM.Mapping.User.dcm.xml | 2 +- .../Doctrine.Tests.ORM.Mapping.User.dcm.yml | 1 + 59 files changed, 159 insertions(+), 211 deletions(-) diff --git a/UPGRADE_TO_2_0 b/UPGRADE_TO_2_0 index fb34f1f9a3d..379d364dbc4 100644 --- a/UPGRADE_TO_2_0 +++ b/UPGRADE_TO_2_0 @@ -46,7 +46,7 @@ Prefer PHP default values, if possible. ## Partial Objects -xxx +[TBD: New syntax, results, etc.] ## XML Mapping Driver diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index 51dc089f9e0..f3bea4f8ef1 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -217,7 +217,7 @@ - + @@ -237,6 +237,7 @@ + @@ -246,7 +247,7 @@ - + @@ -264,6 +265,7 @@ + @@ -274,9 +276,10 @@ + - + diff --git a/lib/Doctrine/Common/EventArgs.php b/lib/Doctrine/Common/EventArgs.php index bfd05b4dc42..6a3c0699ad2 100644 --- a/lib/Doctrine/Common/EventArgs.php +++ b/lib/Doctrine/Common/EventArgs.php @@ -26,7 +26,7 @@ * * This class contains no event data. It is used by events that do not pass state * information to an event handler when an event is raised. The single empty EventArgs - * instance can be obtained through {@link getEmptyInstance()}. + * instance can be obtained through {@link getEmptyInstance}. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org diff --git a/lib/Doctrine/Common/EventSubscriber.php b/lib/Doctrine/Common/EventSubscriber.php index d095af094d4..8e55973bd05 100644 --- a/lib/Doctrine/Common/EventSubscriber.php +++ b/lib/Doctrine/Common/EventSubscriber.php @@ -16,7 +16,7 @@ * * This software consists of voluntary contributions made by many individuals * and is licensed under the LGPL. For more information, see - * . + * . */ namespace Doctrine\Common; @@ -24,13 +24,12 @@ /** * An EventSubscriber knows himself what events he is interested in. * If an EventSubscriber is added to an EventManager, the manager invokes - * getSubscribedEvents() and registers the subscriber as a listener for all + * {@link getSubscribedEvents} and registers the subscriber as a listener for all * returned events. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org * @since 2.0 - * @version $Revision: 3938 $ * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel @@ -38,7 +37,7 @@ interface EventSubscriber { /** - * Returns an array of events that this subscriber listens + * Returns an array of events this subscriber wants to listen to. * * @return array */ diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index cc13676d6ad..ffab1a334d7 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -87,8 +87,8 @@ protected function _prepare() if ($assoc->mappedBy) { $this->_hints['fetched'][$className][$assoc->mappedBy] = true; } else { - if (isset($class->inverseMappings[$sourceClassName][$assoc->sourceFieldName])) { - $inverseAssoc = $class->inverseMappings[$sourceClassName][$assoc->sourceFieldName]; + if ($assoc->inversedBy) { + $inverseAssoc = $class->associationMappings[$assoc->inversedBy]; if ($inverseAssoc->isOneToOne()) { $this->_hints['fetched'][$className][$inverseAssoc->sourceFieldName] = true; if ($class->subClasses) { @@ -346,9 +346,10 @@ protected function _hydrateRow(array $data, array &$cache, array &$result) $this->_uow->setOriginalEntityProperty($oid, $relationField, $element); $targetClass = $this->_ce[$relation->targetEntityName]; if ($relation->isOwningSide) { + //TODO: Just check hints['fetched'] here? // If there is an inverse mapping on the target class its bidirectional - if (isset($targetClass->inverseMappings[$relation->sourceEntityName][$relationField])) { - $inverseAssoc = $targetClass->inverseMappings[$relation->sourceEntityName][$relationField]; + if ($relation->inversedBy) { + $inverseAssoc = $targetClass->associationMappings[$relation->inversedBy]; if ($inverseAssoc->isOneToOne()) { $targetClass->reflFields[$inverseAssoc->sourceFieldName]->setValue($element, $parentObject); $this->_uow->setOriginalEntityProperty(spl_object_hash($element), $inverseAssoc->sourceFieldName, $parentObject); diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 92f4033248e..aa16d865d48 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -315,7 +315,6 @@ public function __sleep() 'idGenerator', //TODO: Does not really need to be serialized. Could be moved to runtime. 'inheritanceType', 'inheritedAssociationFields', - 'inverseMappings', //TODO: Remove! DDC-193 'isIdentifierComposite', 'isMappedSuperclass', 'isVersioned', diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index a38bb1b99c4..b3ed57d98c9 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -127,9 +127,9 @@ class ClassMetadataInfo public $namespace; /** - * READ-ONLY: The name of the entity class that is at the root of the entity inheritance - * hierarchy. If the entity is not part of an inheritance hierarchy this is the same - * as $_entityName. + * READ-ONLY: The name of the entity class that is at the root of the mapped entity inheritance + * hierarchy. If the entity is not part of a mapped inheritance hierarchy this is the same + * as {@link $entityName}. * * @var string */ @@ -312,14 +312,6 @@ class ClassMetadataInfo */ public $associationMappings = array(); - /** - * READ-ONLY: List of inverse association mappings, indexed by mappedBy field name. - * - * @var array - * @todo Remove! See http://www.doctrine-project.org/jira/browse/DDC-193 - */ - public $inverseMappings = array(); - /** * READ-ONLY: Flag indicating whether the identifier/primary key of the class is composite. * @@ -531,34 +523,6 @@ public function getAssociationMapping($fieldName) return $this->associationMappings[$fieldName]; } - /** - * Gets the inverse association mapping for the given target class name and - * owning fieldname. - * - * @param string $mappedByFieldName The field on the - * @return Doctrine\ORM\Mapping\AssociationMapping The mapping or NULL if there is no such - * inverse association mapping. - */ - public function getInverseAssociationMapping($targetClassName, $mappedByFieldName) - { - return isset($this->inverseMappings[$targetClassName][$mappedByFieldName]) ? - $this->inverseMappings[$targetClassName][$mappedByFieldName] : null; - } - - /** - * Checks whether the class has an inverse association mapping that points to the - * specified class and ha the specified mappedBy field. - * - * @param string $targetClassName The name of the target class. - * @param string $mappedByFieldName The name of the mappedBy field that points to the field on - * the target class that owns the association. - * @return boolean - */ - public function hasInverseAssociationMapping($targetClassName, $mappedByFieldName) - { - return isset($this->inverseMappings[$targetClassName][$mappedByFieldName]); - } - /** * Gets all association mappings of the class. * @@ -1063,7 +1027,6 @@ public function addAssociationMapping(AssociationMapping $mapping, $owningClassN if ($owningClassName !== null) { $this->inheritedAssociationFields[$sourceFieldName] = $owningClassName; } - $this->_registerMappingIfInverse($mapping); } /** @@ -1093,20 +1056,6 @@ public function mapOneToOne(array $mapping) $this->_storeAssociationMapping($oneToOneMapping); } - /** - * Registers the mapping as an inverse mapping, if it is a mapping on the - * inverse side of an association mapping. - * - * @param AssociationMapping The mapping to register as inverse if it is a mapping - * for the inverse side of an association. - */ - private function _registerMappingIfInverse(AssociationMapping $assoc) - { - if ( ! $assoc->isOwningSide) { - $this->inverseMappings[$assoc->targetEntityName][$assoc->mappedBy] = $assoc; - } - } - /** * Adds a one-to-many mapping. * @@ -1154,7 +1103,6 @@ protected function _storeAssociationMapping(AssociationMapping $assocMapping) throw MappingException::duplicateFieldMapping($this->name, $sourceFieldName); } $this->associationMappings[$sourceFieldName] = $assocMapping; - $this->_registerMappingIfInverse($assocMapping); } /** diff --git a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php index daab7b531eb..29dedf3e1f5 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php @@ -55,7 +55,7 @@ abstract class AbstractFileDriver implements Driver * @var string */ protected $_fileExtension; - + /** * Initializes a new FileDriver that looks in the given path(s) for mapping * documents and operates in the specified operating mode. @@ -76,7 +76,7 @@ public function addPaths(array $paths) { $this->_paths = array_unique(array_merge($this->_paths, $paths)); } - + /** * Retrieve the defined metadata lookup paths. * @@ -107,7 +107,7 @@ public function setFileExtension($fileExtension) { $this->_fileExtension = $fileExtension; } - + /** * Get the element of schema meta data for the class from the mapping file. * This will lazily load the mapping file if it is not loaded yet @@ -132,7 +132,7 @@ public function getElement($className) public function isTransient($className) { $fileName = str_replace('\\', '.', $className) . $this->_fileExtension; - + // Check whether file exists foreach ((array) $this->_paths as $path) { if (file_exists($path . DIRECTORY_SEPARATOR . $fileName)) { @@ -142,7 +142,7 @@ public function isTransient($className) return true; } - + /** * Gets the names of all mapped classes known to this driver. * @@ -151,7 +151,7 @@ public function isTransient($className) public function getAllClassNames() { $classes = array(); - + if ($this->_paths) { foreach ((array) $this->_paths as $path) { if ( ! is_dir($path)) { diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index e0a53394c7c..8e01479f784 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -173,7 +173,7 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) // Evaluate InheritanceType annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\InheritanceType'])) { $inheritanceTypeAnnot = $classAnnotations['Doctrine\ORM\Mapping\InheritanceType']; - $metadata->setInheritanceType(constant('\Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value)); + $metadata->setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value)); } // Evaluate DiscriminatorColumn annotation @@ -195,7 +195,7 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) // Evaluate DoctrineChangeTrackingPolicy annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\ChangeTrackingPolicy'])) { $changeTrackingAnnot = $classAnnotations['Doctrine\ORM\Mapping\ChangeTrackingPolicy']; - $metadata->setChangeTrackingPolicy(constant('\Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value)); + $metadata->setChangeTrackingPolicy(constant('Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value)); } // Evaluate annotations on properties/fields diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index ecfc71102ba..083583ac7a7 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -29,7 +29,7 @@ Doctrine\Common\Util\Inflector; /** - * The DatabaseDriver reverse engineers the mapping metadata from a database + * The DatabaseDriver reverse engineers the mapping metadata from a database. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org @@ -67,7 +67,7 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) $columns = $this->_sm->listTableColumns($tableName); - if($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { $foreignKeys = $this->_sm->listTableForeignKeys($tableName); } else { $foreignKeys = array(); diff --git a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php index 3c4e7415ec3..537aaf3a399 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php @@ -37,7 +37,6 @@ final class DiscriminatorColumn extends Annotation { public $length; } final class DiscriminatorMap extends Annotation {} -/*final class SubClasses extends Annotation {}*/ final class Id extends Annotation {} final class GeneratedValue extends Annotation { public $strategy = 'AUTO'; @@ -124,7 +123,6 @@ final class SequenceGenerator extends Annotation { public $initialValue = 1; } final class ChangeTrackingPolicy extends Annotation {} - final class OrderBy extends Annotation {} /* Annotations for lifecycle callbacks */ diff --git a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php index dcc461840d2..cd2a727fec3 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DriverChain.php @@ -46,7 +46,7 @@ class DriverChain implements Driver private $_drivers = array(); /** - * Add a nested driver + * Add a nested driver. * * @param Driver $nestedDriver * @param string $namespace @@ -57,7 +57,7 @@ public function addDriver(Driver $nestedDriver, $namespace) } /** - * Get the array of nested drivers + * Get the array of nested drivers. * * @return array $drivers */ @@ -74,7 +74,7 @@ public function getDrivers() */ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) { - foreach ($this->_drivers AS $namespace => $driver) { + foreach ($this->_drivers as $namespace => $driver) { if (strpos($className, $namespace) === 0) { $driver->loadMetadataForClass($className, $metadata); return; diff --git a/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php b/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php index 28863750552..6b6954b83b4 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/PhpDriver.php @@ -49,7 +49,6 @@ class PhpDriver extends AbstractFileDriver * {@inheritdoc} */ protected $_fileExtension = '.php'; - protected $_metadata; /** diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index e02c3bdf5d1..40608d001c8 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -21,7 +21,8 @@ namespace Doctrine\ORM\Mapping\Driver; -use Doctrine\ORM\Mapping\ClassMetadataInfo, +use SimpleXMLElement, + Doctrine\ORM\Mapping\ClassMetadataInfo, Doctrine\ORM\Mapping\MappingException; /** @@ -226,6 +227,9 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) if (isset($oneToOneElement['mapped-by'])) { $mapping['mappedBy'] = (string)$oneToOneElement['mapped-by']; } else { + if (isset($oneToOneElement['inversed-by'])) { + $mapping['inversedBy'] = (string)$oneToOneElement['inversed-by']; + } $joinColumns = array(); if (isset($oneToOneElement->{'join-column'})) { @@ -295,9 +299,13 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) if (isset($manyToOneElement['fetch'])) { $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . (string)$manyToOneElement['fetch']); } - + + if (isset($manyToOneElement['inversed-by'])) { + $mapping['inversedBy'] = (string)$manyToOneElement['inversed-by']; + } + $joinColumns = array(); - + if (isset($manyToOneElement->{'join-column'})) { $joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'}); } else if (isset($manyToOneElement->{'join-columns'})) { @@ -305,13 +313,12 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) if (!isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $name; } - $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); } } - + $mapping['joinColumns'] = $joinColumns; - + if (isset($manyToOneElement->cascade)) { $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade); } @@ -339,11 +346,15 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) if (isset($manyToManyElement['mapped-by'])) { $mapping['mappedBy'] = (string)$manyToManyElement['mapped-by']; } else if (isset($manyToManyElement->{'join-table'})) { + if (isset($manyToManyElement['inversed-by'])) { + $mapping['inversedBy'] = (string)$manyToManyElement['inversed-by']; + } + $joinTableElement = $manyToManyElement->{'join-table'}; $joinTable = array( 'name' => (string)$joinTableElement['name'] ); - + if (isset($joinTableElement['schema'])) { $joinTable['schema'] = (string)$joinTableElement['schema']; } @@ -382,7 +393,7 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) // Evaluate if (isset($xmlRoot->{'lifecycle-callbacks'})) { foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) { - $metadata->addLifecycleCallback((string)$lifecycleCallback['method'], constant('\Doctrine\ORM\Events::' . (string)$lifecycleCallback['type'])); + $metadata->addLifecycleCallback((string)$lifecycleCallback['method'], constant('Doctrine\ORM\Events::' . (string)$lifecycleCallback['type'])); } } } @@ -394,7 +405,7 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) * @param $joinColumnElement The XML element. * @return array The mapping array. */ - private function _getJoinColumnMapping(\SimpleXMLElement $joinColumnElement) + private function _getJoinColumnMapping(SimpleXMLElement $joinColumnElement) { $joinColumn = array( 'name' => (string)$joinColumnElement['name'], diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index a1e9d880479..f5448ff1f4a 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -230,6 +230,10 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) if (isset($oneToOneElement['mappedBy'])) { $mapping['mappedBy'] = $oneToOneElement['mappedBy']; } else { + if (isset($oneToOneElement['inversedBy'])) { + $mapping['inversedBy'] = $oneToOneElement['inversedBy']; + } + $joinColumns = array(); if (isset($oneToOneElement['joinColumn'])) { @@ -292,6 +296,10 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) $mapping['fetch'] = constant('Doctrine\ORM\Mapping\AssociationMapping::FETCH_' . $manyToOneElement['fetch']); } + if (isset($manyToOneElement['inversedBy'])) { + $mapping['inversedBy'] = $manyToOneElement['inversedBy']; + } + $joinColumns = array(); if (isset($manyToOneElement['joinColumn'])) { @@ -331,6 +339,10 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) if (isset($manyToManyElement['mappedBy'])) { $mapping['mappedBy'] = $manyToManyElement['mappedBy']; } else if (isset($manyToManyElement['joinTable'])) { + if (isset($manyToManyElement['inversedBy'])) { + $mapping['inversedBy'] = $manyToManyElement['inversedBy']; + } + $joinTableElement = $manyToManyElement['joinTable']; $joinTable = array( 'name' => $joinTableElement['name'] @@ -375,7 +387,7 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata) if (isset($element['lifecycleCallbacks'])) { foreach ($element['lifecycleCallbacks'] as $type => $methods) { foreach ($methods as $method) { - $metadata->addLifecycleCallback($method, constant('\Doctrine\ORM\Events::' . $type)); + $metadata->addLifecycleCallback($method, constant('Doctrine\ORM\Events::' . $type)); } } } diff --git a/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php b/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php index 3f92c63a70f..95aad2b4142 100644 --- a/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php +++ b/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php @@ -70,10 +70,7 @@ class ManyToManyMapping extends AssociationMapping public $orderBy; /** - * Validates and completes the mapping. - * - * @param array $mapping - * @override + * {@inheritdoc} */ protected function _validateAndCompleteMapping(array $mapping) { @@ -89,13 +86,15 @@ protected function _validateAndCompleteMapping(array $mapping) 'joinColumns' => array( array( 'name' => $sourceShortName . '_id', - 'referencedColumnName' => 'id' + 'referencedColumnName' => 'id', + 'onDelete' => 'CASCADE' ) ), 'inverseJoinColumns' => array( array( 'name' => $targetShortName . '_id', - 'referencedColumnName' => 'id' + 'referencedColumnName' => 'id', + 'onDelete' => 'CASCADE' ) ) ); @@ -178,6 +177,7 @@ public function load($sourceEntity, $targetCollection, $em, array $joinColumnVal $persister->loadManyToManyCollection($this, $joinTableConditions, $targetCollection); } + /** {@inheritdoc} */ public function isManyToMany() { return true; diff --git a/lib/Doctrine/ORM/Mapping/OneToOneMapping.php b/lib/Doctrine/ORM/Mapping/OneToOneMapping.php index 051d943244b..c82558fb44d 100644 --- a/lib/Doctrine/ORM/Mapping/OneToOneMapping.php +++ b/lib/Doctrine/ORM/Mapping/OneToOneMapping.php @@ -141,18 +141,14 @@ public function load($sourceEntity, $targetEntity, $em, array $joinColumnValues $targetClass = $em->getClassMetadata($this->targetEntityName); if ($this->isOwningSide) { - $inverseField = isset($targetClass->inverseMappings[$this->sourceEntityName][$this->sourceFieldName]) ? - $targetClass->inverseMappings[$this->sourceEntityName][$this->sourceFieldName]->sourceFieldName - : false; - // Mark inverse side as fetched in the hints, otherwise the UoW would // try to load it in a separate query (remember: to-one inverse sides can not be lazy). $hints = array(); - if ($inverseField) { - $hints['fetched'][$targetClass->name][$inverseField] = true; + if ($this->inversedBy) { + $hints['fetched'][$targetClass->name][$this->inversedBy] = true; if ($targetClass->subClasses) { foreach ($targetClass->subClasses as $targetSubclassName) { - $hints['fetched'][$targetSubclassName][$inverseField] = true; + $hints['fetched'][$targetSubclassName][$this->inversedBy] = true; } } } @@ -164,8 +160,8 @@ public function load($sourceEntity, $targetEntity, $em, array $joinColumnValues $targetEntity = $em->getUnitOfWork()->getEntityPersister($this->targetEntityName)->load($joinColumnValues, $targetEntity, $this, $hints); - if ($targetEntity !== null && $inverseField && ! $targetClass->isCollectionValuedAssociation($inverseField)) { - $targetClass->reflFields[$inverseField]->setValue($targetEntity, $sourceEntity); + if ($targetEntity !== null && $this->inversedBy && ! $targetClass->isCollectionValuedAssociation($this->inversedBy)) { + $targetClass->reflFields[$this->inversedBy]->setValue($targetEntity, $sourceEntity); } } else { $conditions = array(); diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index d19537c273a..ef8e82dbf37 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -134,18 +134,7 @@ public function setOwner($entity, AssociationMapping $assoc) { $this->_owner = $entity; $this->_association = $assoc; - - // Check for bidirectionality - //$this->_backRefFieldName = $assoc->inversedBy ?: $assoc->mappedBy; - if ( ! $assoc->isOwningSide) { - // For sure bi-directional - $this->_backRefFieldName = $assoc->mappedBy; - } else { - if (isset($this->_typeClass->inverseMappings[$assoc->sourceEntityName][$assoc->sourceFieldName])) { - // Bi-directional - $this->_backRefFieldName = $this->_typeClass->inverseMappings[$assoc->sourceEntityName][$assoc->sourceFieldName]->sourceFieldName; - } - } + $this->_backRefFieldName = $assoc->inversedBy ?: $assoc->mappedBy; } /** @@ -174,8 +163,8 @@ public function getTypeClass() public function hydrateAdd($element) { $this->_coll->add($element); - // If _backRefFieldName is set, then the association is bidirectional - // and we need to set the back reference. + // If _backRefFieldName is set and its a one-to-many association, + // we need to set the back reference. if ($this->_backRefFieldName && $this->_association->isOneToMany()) { // Set back reference to owner $this->_typeClass->reflFields[$this->_backRefFieldName] diff --git a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php index 9b40e6372fe..cf8c7ff8d2f 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractCollectionPersister.php @@ -50,7 +50,7 @@ abstract class AbstractCollectionPersister protected $_uow; /** - * Initializes a new instance of a class derived from {@link AbstractCollectionPersister}. + * Initializes a new instance of a class derived from AbstractCollectionPersister. * * @param Doctrine\ORM\EntityManager $em */ diff --git a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php index a02a9b1913a..cea3f37bdd2 100644 --- a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php @@ -492,8 +492,8 @@ public function refresh(array $id, $entity) if ($found = $this->_em->getUnitOfWork()->tryGetById($joinColumnValues, $targetClass->rootEntityName)) { $this->_class->reflFields[$field]->setValue($entity, $found); // Complete inverse side, if necessary. - if (isset($targetClass->inverseMappings[$this->_class->name][$field])) { - $inverseAssoc = $targetClass->inverseMappings[$this->_class->name][$field]; + if ($assoc->inversedBy) { + $inverseAssoc = $targetClass->associationMappings[$assoc->inversedBy]; $targetClass->reflFields[$inverseAssoc->sourceFieldName]->setValue($found, $entity); } $newData[$field] = $found; diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index d1a89bed418..46628c904f6 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1336,12 +1336,12 @@ private function _doMerge($entity, array &$visited, $prevManagedCopy = null, $as // We need to fetch the managed copy in order to merge. $managedCopy = $this->_em->find($class->name, $id); } - + if ($managedCopy === null) { throw new \InvalidArgumentException('New entity detected during merge.' . ' Persist the new entity before merging.'); } - + if ($class->isVersioned) { $managedCopyVersion = $class->reflFields[$class->versionField]->getValue($managedCopy); $entityVersion = $class->reflFields[$class->versionField]->getValue($entity); @@ -1350,7 +1350,7 @@ private function _doMerge($entity, array &$visited, $prevManagedCopy = null, $as throw OptimisticLockException::lockFailed(); } } - + // Merge state of $entity into existing (managed) entity foreach ($class->reflFields as $name => $prop) { if ( ! isset($class->associationMappings[$name])) { @@ -1359,7 +1359,7 @@ private function _doMerge($entity, array &$visited, $prevManagedCopy = null, $as $assoc2 = $class->associationMappings[$name]; if ($assoc2->isOneToOne()) { if ( ! $assoc2->isCascadeMerge) { - $other = $class->reflFields[$name]->getValue($entity); + $other = $class->reflFields[$name]->getValue($entity); //TODO: Just $prop->getValue($entity)? if ($other !== null) { $targetClass = $this->_em->getClassMetadata($assoc2->targetEntityName); $id = $targetClass->getIdentifierValues($other); diff --git a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php index 746697d32a4..32af0fd85fd 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php @@ -13,23 +13,22 @@ class CmsAddress { /** * @Column(type="integer") - * @Id - * @GeneratedValue(strategy="AUTO") + * @Id @GeneratedValue */ public $id; /** - * @Column(type="string", length=50) + * @Column(length=50) */ public $country; /** - * @Column(type="string", length=50) + * @Column(length=50) */ public $zip; /** - * @Column(type="string", length=50) + * @Column(length=50) */ public $city; @@ -39,8 +38,7 @@ class CmsAddress public $street; /** - * @OneToOne(targetEntity="CmsUser") -// * @JoinColumn(name="user_id", referencedColumnName="id") + * @OneToOne(targetEntity="CmsUser", inversedBy="address") */ public $user; diff --git a/tests/Doctrine/Tests/Models/CMS/CmsArticle.php b/tests/Doctrine/Tests/Models/CMS/CmsArticle.php index 53c49540c27..1d790155785 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsArticle.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsArticle.php @@ -23,7 +23,7 @@ class CmsArticle */ public $text; /** - * @ManyToOne(targetEntity="CmsUser") + * @ManyToOne(targetEntity="CmsUser", inversedBy="articles") * @JoinColumn(name="user_id", referencedColumnName="id") */ public $user; diff --git a/tests/Doctrine/Tests/Models/CMS/CmsComment.php b/tests/Doctrine/Tests/Models/CMS/CmsComment.php index c1991474f26..a40940bca16 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsComment.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsComment.php @@ -23,7 +23,7 @@ class CmsComment */ public $text; /** - * @ManyToOne(targetEntity="CmsArticle") + * @ManyToOne(targetEntity="CmsArticle", inversedBy="comments") * @JoinColumn(name="article_id", referencedColumnName="id") */ public $article; diff --git a/tests/Doctrine/Tests/Models/CMS/CmsEmployee.php b/tests/Doctrine/Tests/Models/CMS/CmsEmployee.php index 9acdbc6f4e5..c1697150fc4 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsEmployee.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsEmployee.php @@ -14,12 +14,12 @@ class CmsEmployee /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ private $id; /** - * @Column(type="string") + * @Column */ private $name; diff --git a/tests/Doctrine/Tests/Models/CMS/CmsGroup.php b/tests/Doctrine/Tests/Models/CMS/CmsGroup.php index 3bdfcba1f34..ad399ba182b 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsGroup.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsGroup.php @@ -18,11 +18,11 @@ class CmsGroup /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ public $id; /** - * @Column(type="string", length=50) + * @Column(length=50) */ public $name; /** diff --git a/tests/Doctrine/Tests/Models/CMS/CmsPhonenumber.php b/tests/Doctrine/Tests/Models/CMS/CmsPhonenumber.php index 39fd7b8f302..431b8c8aedb 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsPhonenumber.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsPhonenumber.php @@ -9,11 +9,11 @@ class CmsPhonenumber { /** - * @Id @Column(type="string", length=50) + * @Id @Column(length=50) */ public $phonenumber; /** - * @ManyToOne(targetEntity="CmsUser") + * @ManyToOne(targetEntity="CmsUser", inversedBy="phonenumbers") * @JoinColumn(name="user_id", referencedColumnName="id") */ public $user; diff --git a/tests/Doctrine/Tests/Models/CMS/CmsUser.php b/tests/Doctrine/Tests/Models/CMS/CmsUser.php index 148fa667442..d7f0727c026 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsUser.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsUser.php @@ -40,7 +40,7 @@ class CmsUser */ public $address; /** - * @ManyToMany(targetEntity="CmsGroup", cascade={"persist"}) + * @ManyToMany(targetEntity="CmsGroup", inversedBy="users", cascade={"persist"}) * @JoinTable(name="cms_users_groups", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")} diff --git a/tests/Doctrine/Tests/Models/Company/CompanyEvent.php b/tests/Doctrine/Tests/Models/Company/CompanyEvent.php index 12252a7d191..f0bb730cf1b 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyEvent.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyEvent.php @@ -11,12 +11,12 @@ class CompanyEvent { /** * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ private $id; /** - * @ManyToOne(targetEntity="CompanyOrganization",cascade={"persist"}) + * @ManyToOne(targetEntity="CompanyOrganization", inversedBy="events", cascade={"persist"}) * @JoinColumn(name="org_id", referencedColumnName="id") */ private $organization; diff --git a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php index c38dc742845..740c323ef0f 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php @@ -20,11 +20,11 @@ class CompanyPerson /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ private $id; /** - * @Column(type="string") + * @Column */ private $name; /** diff --git a/tests/Doctrine/Tests/Models/Company/CompanyRaffle.php b/tests/Doctrine/Tests/Models/Company/CompanyRaffle.php index a7d123c84c3..3d05996f273 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyRaffle.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyRaffle.php @@ -4,7 +4,7 @@ /** @Entity @Table(name="company_raffles") */ class CompanyRaffle extends CompanyEvent { - /** @Column(type="string") */ + /** @Column */ private $data; public function setData($data) { diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php index 8fac69be07c..d68b37056ca 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php @@ -17,17 +17,17 @@ class ECommerceCart /** * @Column(type="integer") * @Id - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ private $id; /** - * @Column(type="string", length=50, nullable=true) + * @Column(length=50, nullable=true) */ private $payment; /** - * @OneToOne(targetEntity="ECommerceCustomer") + * @OneToOne(targetEntity="ECommerceCustomer", inversedBy="cart") * @JoinColumn(name="customer_id", referencedColumnName="id") */ private $customer; diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCategory.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCategory.php index d79c1a2987a..ea2ade09d1b 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCategory.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCategory.php @@ -36,7 +36,7 @@ class ECommerceCategory private $children; /** - * @ManyToOne(targetEntity="ECommerceCategory") + * @ManyToOne(targetEntity="ECommerceCategory", inversedBy="children") * @JoinColumn(name="parent_id", referencedColumnName="id") */ private $parent; diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceFeature.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceFeature.php index 901e7c1e95e..8f6cdd98357 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceFeature.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceFeature.php @@ -14,17 +14,17 @@ class ECommerceFeature /** * @Column(type="integer") * @Id - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ private $id; /** - * @Column(type="string", length=50) + * @Column(length=50) */ private $description; /** - * @ManyToOne(targetEntity="ECommerceProduct") + * @ManyToOne(targetEntity="ECommerceProduct", inversedBy="features") * @JoinColumn(name="product_id", referencedColumnName="id") */ private $product; diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php index 40fe67bd839..4851778e216 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php @@ -10,14 +10,14 @@ * * @author Giorgio Sironi * @Entity - * @Table(name="ecommerce_products",indexes={@index(name="name_idx", columns={"name"})}) + * @Table(name="ecommerce_products",indexes={@Index(name="name_idx", columns={"name"})}) */ class ECommerceProduct { /** * @Column(type="integer") * @Id - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ private $id; @@ -38,7 +38,7 @@ class ECommerceProduct private $features; /** - * @ManyToMany(targetEntity="ECommerceCategory", cascade={"persist"}) + * @ManyToMany(targetEntity="ECommerceCategory", cascade={"persist"}, inversedBy="products") * @JoinTable(name="ecommerce_products_categories", * joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")}, * inverseJoinColumns={@JoinColumn(name="category_id", referencedColumnName="id")}) @@ -50,8 +50,8 @@ class ECommerceProduct * simplicity. * @ManyToMany(targetEntity="ECommerceProduct", cascade={"persist"}) * @JoinTable(name="ecommerce_products_related", - joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")}, - inverseJoinColumns={@JoinColumn(name="related_id", referencedColumnName="id")}) + * joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")}, + * inverseJoinColumns={@JoinColumn(name="related_id", referencedColumnName="id")}) */ private $related; diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceShipping.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceShipping.php index b1ee90a53e3..a0f302cc22f 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceShipping.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceShipping.php @@ -14,7 +14,7 @@ class ECommerceShipping { /** * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ private $id; diff --git a/tests/Doctrine/Tests/Models/Forum/ForumBoard.php b/tests/Doctrine/Tests/Models/Forum/ForumBoard.php index 6496dd9a1d9..707d3630955 100644 --- a/tests/Doctrine/Tests/Models/Forum/ForumBoard.php +++ b/tests/Doctrine/Tests/Models/Forum/ForumBoard.php @@ -21,7 +21,7 @@ class ForumBoard */ public $position; /** - * @ManyToOne(targetEntity="ForumCategory") + * @ManyToOne(targetEntity="ForumCategory", inversedBy="boards") * @JoinColumn(name="category_id", referencedColumnName="id") */ public $category; diff --git a/tests/Doctrine/Tests/Models/Forum/ForumUser.php b/tests/Doctrine/Tests/Models/Forum/ForumUser.php index fedf1095594..e276231605a 100644 --- a/tests/Doctrine/Tests/Models/Forum/ForumUser.php +++ b/tests/Doctrine/Tests/Models/Forum/ForumUser.php @@ -10,8 +10,7 @@ class ForumUser { /** * @Column(type="integer") - * @Id - * @GeneratedValue(strategy="AUTO") + * @Id @GeneratedValue */ public $id; /** diff --git a/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php b/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php index 365268a5418..0733245ffd6 100644 --- a/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php +++ b/tests/Doctrine/Tests/Models/Generic/DateTimeModel.php @@ -10,7 +10,7 @@ class DateTimeModel { /** * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ public $id; /** diff --git a/tests/Doctrine/Tests/Models/Routing/RoutingLeg.php b/tests/Doctrine/Tests/Models/Routing/RoutingLeg.php index 64564d3ef70..a130e7b0c4d 100644 --- a/tests/Doctrine/Tests/Models/Routing/RoutingLeg.php +++ b/tests/Doctrine/Tests/Models/Routing/RoutingLeg.php @@ -8,20 +8,19 @@ class RoutingLeg { /** - * @Id - * @generatedValue(strategy="AUTO") + * @Id @generatedValue * @column(type="integer") */ public $id; /** - * @ManyToOne(targetEntity="Doctrine\Tests\Models\Routing\RoutingLocation") + * @ManyToOne(targetEntity="RoutingLocation") * @JoinColumn(name="from_id", referencedColumnName="id") */ public $fromLocation; /** - * @ManyToOne(targetEntity="Doctrine\Tests\Models\Routing\RoutingLocation") + * @ManyToOne(targetEntity="RoutingLocation") * @JoinColumn(name="to_id", referencedColumnName="id") */ public $toLocation; diff --git a/tests/Doctrine/Tests/Models/Routing/RoutingLocation.php b/tests/Doctrine/Tests/Models/Routing/RoutingLocation.php index 2a04275e862..ea1ba55f787 100644 --- a/tests/Doctrine/Tests/Models/Routing/RoutingLocation.php +++ b/tests/Doctrine/Tests/Models/Routing/RoutingLocation.php @@ -8,8 +8,7 @@ class RoutingLocation { /** - * @Id - * @generatedValue(strategy="AUTO") + * @Id @GeneratedValue * @Column(type="integer") */ public $id; diff --git a/tests/Doctrine/Tests/Models/Routing/RoutingRoute.php b/tests/Doctrine/Tests/Models/Routing/RoutingRoute.php index 0f0f671c135..9e5d5d02e76 100644 --- a/tests/Doctrine/Tests/Models/Routing/RoutingRoute.php +++ b/tests/Doctrine/Tests/Models/Routing/RoutingRoute.php @@ -11,7 +11,7 @@ class RoutingRoute { /** * @Id - * @generatedValue(strategy="AUTO") + * @GeneratedValue * @column(type="integer") */ public $id; diff --git a/tests/Doctrine/Tests/Models/Routing/RoutingRouteBooking.php b/tests/Doctrine/Tests/Models/Routing/RoutingRouteBooking.php index ea2f31f6005..9b862fc3915 100644 --- a/tests/Doctrine/Tests/Models/Routing/RoutingRouteBooking.php +++ b/tests/Doctrine/Tests/Models/Routing/RoutingRouteBooking.php @@ -10,12 +10,12 @@ class RoutingRouteBooking /** * @Id * @Column(type="integer") - * @generatedValue(strategy="AUTO") + * @GeneratedValue */ public $id; /** - * @ManyToOne(targetEntity="RoutingRoute") + * @ManyToOne(targetEntity="RoutingRoute", inversedBy="bookings") * @JoinColumn(name="route_id", referencedColumnName="id") */ public $route; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php index 6c248676bb3..9b493e7da3d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php @@ -43,21 +43,21 @@ public function testIssue() */ class DDC144FlowElement { /** - * @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") + * @Id @Column(type="integer") @GeneratedValue * @var integer */ public $id; - /** @Column(type="string") */ + /** @Column */ public $property; } -// /** @Entity @Table(name="ddc144_expressions") */ abstract class DDC144Expression extends DDC144FlowElement { abstract function method(); } + /** @Entity @Table(name="ddc144_operands") */ class DDC144Operand extends DDC144Expression { - /** @Column(type="string") */ + /** @Column */ public $operandProperty; function method() {} } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php index 08ed3ef9430..e912c389f21 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC199Test.php @@ -79,7 +79,7 @@ class DDC199ParentClass class DDC199ChildClass extends DDC199ParentClass { /** - * @Column(type="string") + * @Column */ public $childData; } @@ -87,13 +87,13 @@ class DDC199ChildClass extends DDC199ParentClass /** @Entity @Table(name="ddc199_relatedclass") */ class DDC199RelatedClass { - /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ + /** @Id @Column(type="integer") @GeneratedValue */ public $id; - /** @Column(type="string") */ + /** @Column */ public $relatedData; /** - * @ManyToOne(targetEntity="DDC199ParentClass") + * @ManyToOne(targetEntity="DDC199ParentClass", inversedBy="relatedEntities") * @JoinColumn(name="parent_id", referencedColumnName="id") */ public $parent; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php index 56a3ddcc83a..27abee236bd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC211Test.php @@ -65,7 +65,7 @@ class DDC211User protected $name; /** - * @ManyToMany(targetEntity="DDC211Group") + * @ManyToMany(targetEntity="DDC211Group", inversedBy="users") * @JoinTable(name="user_groups", * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php index 877b3b86111..6dc23c8952c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC237Test.php @@ -68,7 +68,7 @@ public function testUninitializedProxyIsInitializedOnFetchJoin() class DDC237EntityX { /** - * @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") + * @Id @Column(type="integer") @GeneratedValue */ public $id; /** @@ -87,7 +87,7 @@ class DDC237EntityX class DDC237EntityY { /** - * @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") + * @Id @Column(type="integer") @GeneratedValue */ public $id; /** @@ -99,7 +99,7 @@ class DDC237EntityY /** @Entity @Table(name="ddc237_z") */ class DDC237EntityZ { - /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ + /** @Id @Column(type="integer") @GeneratedValue */ public $id; /** @Column(type="string") */ public $data; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php index e3d4d19492f..50bc5ec1aa1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC279Test.php @@ -68,7 +68,7 @@ abstract class DDC279EntityXAbstract { /** * @Id - * @generatedValue(strategy="AUTO") + * @GeneratedValue * @Column(name="id", type="integer") */ public $id; @@ -98,8 +98,7 @@ class DDC279EntityX extends DDC279EntityXAbstract class DDC279EntityY { /** - * @Id - * @generatedValue(strategy="AUTO") + * @Id @GeneratedValue * @Column(name="id", type="integer") */ public $id; @@ -122,8 +121,7 @@ class DDC279EntityY class DDC279EntityZ { /** - * @Id - * @generatedValue(strategy="AUTO") + * @Id @GeneratedValue * @Column(name="id", type="integer") */ public $id; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php index 728e11d25bb..325ce8d756a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC309Test.php @@ -54,7 +54,7 @@ class DDC309Country /** * @Id * @Column(name="id", type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ public $id; } @@ -67,7 +67,7 @@ class DDC309User /** * @Id * @Column(name="id", type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ public $id; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php index 6ae3732295c..63a084c87b6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php @@ -118,13 +118,13 @@ class DDC345Membership public $id; /** - * @OneToOne(targetEntity="DDC345User") + * @OneToOne(targetEntity="DDC345User", inversedBy="Memberships") * @JoinColumn(name="user_id", referencedColumnName="id", nullable=false) */ public $user; /** - * @OneToOne(targetEntity="DDC345Group") + * @OneToOne(targetEntity="DDC345Group", inversedBy="Memberships") * @JoinColumn(name="group_id", referencedColumnName="id", nullable=false) */ public $group; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php index 8d645121d83..5091cd44cc8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC353Test.php @@ -78,8 +78,7 @@ class DDC353Picture { /** * @Column(name="picture_id", type="integer") - * @Id - * @GeneratedValue(strategy="AUTO") + * @Id @GeneratedValue */ private $pictureId; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php index 8f18a1fc62d..399e35c3470 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC371Test.php @@ -53,7 +53,7 @@ class DDC371Child { private $id; /** @Column(type="string") */ public $data; - /** @ManyToOne(targetEntity="DDC371Parent") @JoinColumn(name="parentId") */ + /** @ManyToOne(targetEntity="DDC371Parent", inversedBy="children") @JoinColumn(name="parentId") */ public $parent; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php index a088ba8cfc8..c25a8aa7509 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php @@ -47,7 +47,7 @@ public function testCallUnserializedProxyMethods() class DDC381Entity { /** - * @Id @Column(type="integer") @generatedValue + * @Id @Column(type="integer") @GeneratedValue */ protected $id; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php index 8b59b4bf3e7..f6ef6c3bfbc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket69.php @@ -212,7 +212,7 @@ class Relation { /** * @var Lemma - * @ManyToOne(targetEntity="Lemma") + * @ManyToOne(targetEntity="Lemma", inversedBy="relations") * @JoinColumn(name="relation_parent_id", referencedColumnName="lemma_id") */ private $parent; @@ -226,7 +226,7 @@ class Relation { /** * @var RelationType - * @ManyToOne(targetEntity="RelationType") + * @ManyToOne(targetEntity="RelationType", inversedBy="relations") * @JoinColumn(name="relation_type_id", referencedColumnName="relation_type_id") */ private $type; diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 9e03211a672..8b29c6bad06 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -73,7 +73,6 @@ public function testIdentifier($class) public function testAssocations($class) { $this->assertEquals(3, count($class->associationMappings)); - $this->assertEquals(1, count($class->inverseMappings)); return $class; } @@ -87,6 +86,7 @@ public function testOwningOneToOneAssocation($class) $this->assertTrue($class->associationMappings['address'] instanceof \Doctrine\ORM\Mapping\OneToOneMapping); $this->assertTrue(isset($class->associationMappings['address'])); $this->assertTrue($class->associationMappings['address']->isOwningSide); + $this->assertEquals('user', $class->associationMappings['address']->inversedBy); // Check cascading $this->assertTrue($class->associationMappings['address']->isCascadeRemove); $this->assertFalse($class->associationMappings['address']->isCascadePersist); @@ -223,13 +223,12 @@ class User public $email; /** - * @OneToOne(targetEntity="Address", cascade={"remove"}) + * @OneToOne(targetEntity="Address", cascade={"remove"}, inversedBy="user") * @JoinColumn(onDelete="CASCADE", onUpdate="CASCADE") */ public $address; /** - * * @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"}) * @OrderBy({"number"="ASC"}) */ diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 11fb499481f..dcc6b8210e3 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -100,8 +100,8 @@ public function testMapManyToManyJoinTableDefaults() $this->assertTrue($assoc instanceof \Doctrine\ORM\Mapping\ManyToManyMapping); $this->assertEquals(array( 'name' => 'CmsUser_CmsGroup', - 'joinColumns' => array(array('name' => 'CmsUser_id', 'referencedColumnName' => 'id')), - 'inverseJoinColumns' => array(array('name' => 'CmsGroup_id', 'referencedColumnName' => 'id')) + 'joinColumns' => array(array('name' => 'CmsUser_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')), + 'inverseJoinColumns' => array(array('name' => 'CmsGroup_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE')) ), $assoc->joinTable); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php index 7bd7fcaf46e..e2a057f1427 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php @@ -39,6 +39,7 @@ 0 => 'remove', ), 'mappedBy' => NULL, + 'inversedBy' => 'user', 'joinColumns' => array( 0 => diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml index 776185a283c..65b71f04c97 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml @@ -20,7 +20,7 @@ - + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml index 5e239da3f0e..3cf687169da 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml @@ -19,6 +19,7 @@ Doctrine\Tests\ORM\Mapping\User: oneToOne: address: targetEntity: Address + inversedBy: user joinColumn: name: address_id referencedColumnName: id