From a75d73b889e2cbeb6900168917a284fbf73603f5 Mon Sep 17 00:00:00 2001 From: Alex Pogodin Date: Sun, 22 Sep 2013 17:19:51 +0300 Subject: [PATCH 1/2] Identifier can be empty for MappedSuperclasses When MappedSuperclass is inspected without identifier column been assigned, always return false. Solves "Undefined offset" notice. --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 9b3b29492..4e89cf883 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1031,6 +1031,9 @@ class ClassMetadataInfo implements ClassMetadata */ public function isIdentifier($fieldName) { + if (0 == count($this->identifier)) { + return false; + } if ( ! $this->isIdentifierComposite) { return $fieldName === $this->identifier[0]; } From 53ed8986849cd73840181f4837826c5db39014ca Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Thu, 2 Jan 2014 23:50:15 +0100 Subject: [PATCH 2/2] [DDC-2700] Add test and fix CS. --- .../ORM/Mapping/ClassMetadataInfo.php | 4 +++- .../Tests/ORM/Mapping/ClassMetadataTest.php | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 4e89cf883..58e527005 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1031,12 +1031,14 @@ class ClassMetadataInfo implements ClassMetadata */ public function isIdentifier($fieldName) { - if (0 == count($this->identifier)) { + if ( ! $this->identifier) { return false; } + if ( ! $this->isIdentifierComposite) { return $fieldName === $this->identifier[0]; } + return in_array($fieldName, $this->identifier); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 67bf4c905..aa284db89 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -1091,6 +1091,25 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(array('sequenceName' => 'foo', 'quoted' => true), $cm->sequenceGeneratorDefinition); } + + /** + * @group DDC-2700 + */ + public function testIsIdentifierMappedSuperClass() + { + $class = new ClassMetadata(__NAMESPACE__ . '\\DDC2700MappedSuperClass'); + + $this->assertFalse($class->isIdentifier('foo')); + } +} + +/** + * @MappedSuperclass + */ +class DDC2700MappedSuperClass +{ + /** @Column */ + private $foo; } class MyNamespacedNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStrategy