Created
December 13, 2015 18:34
-
-
Save doctrinebot/025caa587d88293d9c09 to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-1243 - https://github.com/doctrine/doctrine2/issues/1852
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | |
index 8bfda64..476fbb8 100644 | |
--- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | |
+++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | |
@@ -229,6 +229,27 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface | |
} | |
/** | |
+ * Does the given entity class have an inherited identifier? | |
+ * | |
+ * @param string $name | |
+ * @return true or false | |
+ */ | |
+ protected function hasInheritedIdentifier($name) | |
+ { | |
+ // Collect parent classes, ignoring transient (not-mapped) classes | |
+ // to see if they have an identifier | |
+ foreach (array_reverse(class_parents($name)) as $parentClass) { | |
+ if ( ! $this->driver->isTransient($parentClass)) { | |
+ $parent = $this->loadedMetadata[$parentClass]; | |
+ if (!$parent->isInheritanceTypeNone() && $parent->identifier) { | |
+ return true; | |
+ } | |
+ } | |
+ } | |
+ return false; | |
+ } | |
+ | |
+ /** | |
* Loads the metadata of the class in question and all it's ancestors whose metadata | |
* is still not loaded. | |
* | |
@@ -314,7 +335,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface | |
} | |
// Verify & complete identifier mapping | |
- if ( ! $class->identifier && ! $class->isMappedSuperclass) { | |
+ if ( ! $class->identifier && ! $class->isMappedSuperclass && ! $this->hasInheritedIdentifier($name)) { | |
throw MappingException::identifierRequired($className); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | |
index 8bfda64..2c0838b 100644 | |
--- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | |
+++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | |
@@ -229,6 +229,27 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface | |
} | |
/** | |
+ * Does the given entity class have an inherited identifier? | |
+ * | |
+ * @param string $name | |
+ * @return true or false | |
+ */ | |
+ protected function hasInheritedIdentifier($name) | |
+ { | |
+ // Collect parent classes, ignoring transient (not-mapped) classes | |
+ // to see if they have an identifier | |
+ foreach (array_reverse(class_parents($name)) as $parentClass) { | |
+ if ( ! $this->driver->isTransient($parentClass) && ! empty($this->loadedMetadata[$parentClass])) { | |
+ $parent = $this->loadedMetadata[$parentClass]; | |
+ if (!$parent->isInheritanceTypeNone() && $parent->identifier) { | |
+ return true; | |
+ } | |
+ } | |
+ } | |
+ return false; | |
+ } | |
+ | |
+ /** | |
* Loads the metadata of the class in question and all it's ancestors whose metadata | |
* is still not loaded. | |
* | |
@@ -314,7 +335,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface | |
} | |
// Verify & complete identifier mapping | |
- if ( ! $class->identifier && ! $class->isMappedSuperclass) { | |
+ if ( ! $class->identifier && ! $class->isMappedSuperclass && ! $this->hasInheritedIdentifier($name)) { | |
throw MappingException::identifierRequired($className); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment