diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 8770cb4ac..62ea7bb9b 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -3158,6 +3158,7 @@ class ClassMetadataInfo implements ClassMetadata * Map Embedded Class * * @param array $mapping + * @throws MappingException * @return void */ public function mapEmbedded(array $mapping) @@ -3187,9 +3188,17 @@ class ClassMetadataInfo implements ClassMetadata $fieldMapping['originalField'] = $fieldMapping['fieldName']; $fieldMapping['fieldName'] = $property . "." . $fieldMapping['fieldName']; - $fieldMapping['columnName'] = ! empty($this->embeddedClasses[$property]['columnPrefix']) - ? $this->embeddedClasses[$property]['columnPrefix'] . $fieldMapping['columnName'] - : $this->namingStrategy->embeddedFieldToColumnName($property, $fieldMapping['columnName'], $this->reflClass->name, $embeddable->reflClass->name); + if (! empty($this->embeddedClasses[$property]['columnPrefix'])) { + $fieldMapping['columnName'] = $this->embeddedClasses[$property]['columnPrefix'] . $fieldMapping['columnName']; + } elseif ($this->embeddedClasses[$property]['columnPrefix'] !== false) { + $fieldMapping['columnName'] = $this->namingStrategy + ->embeddedFieldToColumnName( + $property, + $fieldMapping['columnName'], + $this->reflClass->name, + $embeddable->reflClass->name + ); + } $this->mapField($fieldMapping); } diff --git a/lib/Doctrine/ORM/Mapping/Embedded.php b/lib/Doctrine/ORM/Mapping/Embedded.php index b44bced84..37339108b 100644 --- a/lib/Doctrine/ORM/Mapping/Embedded.php +++ b/lib/Doctrine/ORM/Mapping/Embedded.php @@ -32,7 +32,7 @@ final class Embedded implements Annotation public $class; /** - * @var string + * @var mixed */ public $columnPrefix; } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php index 40768f35c..8820fe501 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php @@ -179,8 +179,42 @@ class ValueObjectsTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC93PhoneNumber') )); } + + public function testInlineEmbeddableWithPrefix() + { + $expectedColumnName = 'foobar_id'; + + $actualColumnName = $this->_em + ->getClassMetadata(__NAMESPACE__ . '\DDC3028PersonWithPrefix') + ->getColumnName('id.id'); + + $this->assertEquals($expectedColumnName, $actualColumnName); + } + + public function testInlineEmbeddableEmptyPrefix() + { + $expectedColumnName = 'id_id'; + + $actualColumnName = $this->_em + ->getClassMetadata(__NAMESPACE__ . '\DDC3028PersonEmptyPrefix') + ->getColumnName('id.id'); + + $this->assertEquals($expectedColumnName, $actualColumnName); + } + + public function testInlineEmbeddablePrefixFalse() + { + $expectedColumnName = 'id'; + + $actualColumnName = $this->_em + ->getClassMetadata(__NAMESPACE__ . '\DDC3028PersonPrefixFalse') + ->getColumnName('id.id'); + + $this->assertEquals($expectedColumnName, $actualColumnName); + } } + /** * @Entity */ @@ -296,3 +330,69 @@ class DDC93ContactInfo /** @Embedded(class = "DDC93Address") */ private $address; } + +/** + * @Entity + */ +class DDC3028PersonWithPrefix +{ + const CLASSNAME = __CLASS__; + + /** @Embedded(class="DDC3028Id", columnPrefix = "foobar_") */ + public $id; + + public function __construct(DDC3028Id $id = null) + { + $this->id = $id; + } +} + +/** + * @Entity + */ +class DDC3028PersonEmptyPrefix +{ + const CLASSNAME = __CLASS__; + + /** @Embedded(class="DDC3028Id", columnPrefix = "") */ + public $id; + + public function __construct(DDC3028Id $id = null) + { + $this->id = $id; + } +} + +/** + * @Entity + */ +class DDC3028PersonPrefixFalse +{ + const CLASSNAME = __CLASS__; + + /** @Embedded(class="DDC3028Id", columnPrefix = false) */ + public $id; + + public function __construct(DDC3028Id $id = null) + { + $this->id = $id; + } +} + +/** + * @Embeddable + */ +class DDC3028Id +{ + const CLASSNAME = __CLASS__; + + /** + * @Id @Column(type="string") + */ + public $id; + + public function __construct($id = null) + { + $this->id = $id; + } +}