1
0
mirror of synced 2024-12-05 03:06:05 +03:00

columnPrefix must support string and boolean, so changing to mixed

This commit is contained in:
Anton Stoeckl 2014-03-14 12:29:01 +01:00
parent fa79de6ea4
commit cd2043915c
3 changed files with 121 additions and 4 deletions

View File

@ -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,21 @@ class ClassMetadataInfo implements ClassMetadata
$fieldMapping['originalField'] = $fieldMapping['fieldName'];
$fieldMapping['fieldName'] = $property . "." . $fieldMapping['fieldName'];
$fieldMapping['columnName'] = ! empty($this->embeddedClasses[$property]['columnPrefix']) || $this->embeddedClasses[$property]['columnPrefix'] === false
? $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
);
}
// $fieldMapping['columnName'] = ! empty($this->embeddedClasses[$property]['columnPrefix']) || $this->embeddedClasses[$property]['columnPrefix'] === false
// ? $this->embeddedClasses[$property]['columnPrefix'] . $fieldMapping['columnName']
// : $this->namingStrategy->embeddedFieldToColumnName($property, $fieldMapping['columnName'], $this->reflClass->name, $embeddable->reflClass->name);
$this->mapField($fieldMapping);
}

View File

@ -32,7 +32,7 @@ final class Embedded implements Annotation
public $class;
/**
* @var string
* @var mixed
*/
public $columnPrefix;
}

View File

@ -179,8 +179,46 @@ 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 +334,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;
}
}