1
0
mirror of synced 2025-01-31 20:41:44 +03:00

Merge branch 'feature/#1238-allow-skipping-column-prefixing-in-xml-mapped-embeddables'

Close #1238
This commit is contained in:
Marco Pivetta 2015-01-08 13:33:52 +01:00
commit 0cbab230bf
10 changed files with 149 additions and 4 deletions

View File

@ -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
---

View File

@ -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">

View File

@ -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");
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace Doctrine\Tests\Models\DDC3293;
class DDC3293Address
{
public $street;
public $city;
public $country;
}

View 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;
}

View 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;
}

View File

@ -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');

View File

@ -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>

View File

@ -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>

View File

@ -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>