Merge branch 'feature/#1238-allow-skipping-column-prefixing-in-xml-mapped-embeddables'
Close #1238
This commit is contained in:
commit
0cbab230bf
@ -117,7 +117,7 @@ The following example shows you how to set your prefix to ``myPrefix_``:
|
||||
columnPrefix: myPrefix_
|
||||
|
||||
To have Doctrine drop the prefix and use the value object's property name
|
||||
directly, set ``columnPrefix=false`` (not yet supported with XML configuration):
|
||||
directly, set ``columnPrefix=false`` (``use-column-prefix="false"`` for XML):
|
||||
|
||||
.. configuration-block::
|
||||
|
||||
@ -141,6 +141,12 @@ directly, set ``columnPrefix=false`` (not yet supported with XML configuration):
|
||||
class: Address
|
||||
columnPrefix: false
|
||||
|
||||
.. code-block:: xml
|
||||
|
||||
<entity name="User">
|
||||
<embedded name="address" class="Address" use-column-prefix="false" />
|
||||
</entity>
|
||||
|
||||
|
||||
DQL
|
||||
---
|
||||
|
@ -304,6 +304,7 @@
|
||||
<xs:attribute name="name" type="xs:string" use="required" />
|
||||
<xs:attribute name="class" type="xs:string" use="required" />
|
||||
<xs:attribute name="column-prefix" type="xs:string" use="optional" />
|
||||
<xs:attribute name="use-column-prefix" type="xs:boolean" default="true" use="optional" />
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="discriminator-column">
|
||||
|
@ -255,11 +255,20 @@ class XmlDriver extends FileDriver
|
||||
|
||||
if (isset($xmlRoot->embedded)) {
|
||||
foreach ($xmlRoot->embedded as $embeddedMapping) {
|
||||
$columnPrefix = isset($embeddedMapping['column-prefix'])
|
||||
? (string) $embeddedMapping['column-prefix']
|
||||
: null;
|
||||
|
||||
$useColumnPrefix = isset($embeddedMapping['use-column-prefix'])
|
||||
? $this->evaluateBoolean($embeddedMapping['use-column-prefix'])
|
||||
: true;
|
||||
|
||||
$mapping = array(
|
||||
'fieldName' => (string) $embeddedMapping['name'],
|
||||
'class' => (string) $embeddedMapping['class'],
|
||||
'columnPrefix' => isset($embeddedMapping['column-prefix']) ? (string) $embeddedMapping['column-prefix'] : null,
|
||||
'columnPrefix' => $useColumnPrefix ? $columnPrefix : false
|
||||
);
|
||||
|
||||
$metadata->mapEmbedded($mapping);
|
||||
}
|
||||
}
|
||||
@ -781,7 +790,7 @@ class XmlDriver extends FileDriver
|
||||
*
|
||||
* @return array The list of cascade options.
|
||||
*/
|
||||
private function _getCascadeMappings($cascadeElement)
|
||||
private function _getCascadeMappings(SimpleXMLElement $cascadeElement)
|
||||
{
|
||||
$cascades = array();
|
||||
/* @var $action SimpleXmlElement */
|
||||
@ -833,6 +842,6 @@ class XmlDriver extends FileDriver
|
||||
{
|
||||
$flag = (string)$element;
|
||||
|
||||
return ($flag === true || $flag == "true" || $flag == "1");
|
||||
return ($flag == "true" || $flag == "1");
|
||||
}
|
||||
}
|
||||
|
10
tests/Doctrine/Tests/Models/DDC3293/DDC3293Address.php
Normal file
10
tests/Doctrine/Tests/Models/DDC3293/DDC3293Address.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC3293;
|
||||
|
||||
class DDC3293Address
|
||||
{
|
||||
public $street;
|
||||
public $city;
|
||||
public $country;
|
||||
}
|
16
tests/Doctrine/Tests/Models/DDC3293/DDC3293User.php
Normal file
16
tests/Doctrine/Tests/Models/DDC3293/DDC3293User.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC3293;
|
||||
|
||||
class DDC3293User
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var Doctrine\Tests\Models\DDC3293\DDC3293Address
|
||||
*/
|
||||
protected $address;
|
||||
}
|
16
tests/Doctrine/Tests/Models/DDC3293/DDC3293UserPrefixed.php
Normal file
16
tests/Doctrine/Tests/Models/DDC3293/DDC3293UserPrefixed.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC3293;
|
||||
|
||||
class DDC3293UserPrefixed
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var Doctrine\Tests\Models\DDC3293\DDC3293Address
|
||||
*/
|
||||
protected $address;
|
||||
}
|
@ -57,6 +57,47 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest
|
||||
$this->assertEquals(true, $class->isEmbeddedClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-3293
|
||||
* @group DDC-3477
|
||||
* @group 1238
|
||||
*/
|
||||
public function testEmbeddedMappingsWithUseColumnPrefix()
|
||||
{
|
||||
$factory = new ClassMetadataFactory();
|
||||
$em = $this->_getTestEntityManager();
|
||||
|
||||
$em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver());
|
||||
$factory->setEntityManager($em);
|
||||
|
||||
$this->assertEquals(
|
||||
'__prefix__',
|
||||
$factory
|
||||
->getMetadataFor('Doctrine\Tests\Models\DDC3293\DDC3293UserPrefixed')
|
||||
->embeddedClasses['address']['columnPrefix']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-3293
|
||||
* @group DDC-3477
|
||||
* @group 1238
|
||||
*/
|
||||
public function testEmbeddedMappingsWithFalseUseColumnPrefix()
|
||||
{
|
||||
$factory = new ClassMetadataFactory();
|
||||
$em = $this->_getTestEntityManager();
|
||||
|
||||
$em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver());
|
||||
$factory->setEntityManager($em);
|
||||
|
||||
$this->assertFalse(
|
||||
$factory
|
||||
->getMetadataFor('Doctrine\Tests\Models\DDC3293\DDC3293User')
|
||||
->embeddedClasses['address']['columnPrefix']
|
||||
);
|
||||
}
|
||||
|
||||
public function testEmbeddedMapping()
|
||||
{
|
||||
$class = $this->createClassMetadata('Doctrine\Tests\Models\ValueObjects\Person');
|
||||
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping
|
||||
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
|
||||
<embeddable name="Doctrine\Tests\Models\DDC3293\DDC3293Address">
|
||||
<field name="street" type="string" />
|
||||
<field name="city" type="string" />
|
||||
<field name="country" type="string" />
|
||||
</embeddable>
|
||||
</doctrine-mapping>
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping
|
||||
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
|
||||
<entity name="Doctrine\Tests\Models\DDC3293\DDC3293User" table="user">
|
||||
<id name="id" column="id">
|
||||
<generator strategy="UUID" />
|
||||
</id>
|
||||
<embedded
|
||||
name="address"
|
||||
class="Doctrine\Tests\Models\DDC3293\DDC3293Address"
|
||||
column-prefix="__prefix__"
|
||||
use-column-prefix="false" />
|
||||
</entity>
|
||||
</doctrine-mapping>
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping
|
||||
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
|
||||
<entity name="Doctrine\Tests\Models\DDC3293\DDC3293UserPrefixed" table="user">
|
||||
<id name="id" column="id">
|
||||
<generator strategy="UUID" />
|
||||
</id>
|
||||
<embedded
|
||||
name="address"
|
||||
class="Doctrine\Tests\Models\DDC3293\DDC3293Address"
|
||||
column-prefix="__prefix__"
|
||||
use-column-prefix="true" />
|
||||
</entity>
|
||||
</doctrine-mapping>
|
Loading…
x
Reference in New Issue
Block a user