From 82cda1ecb006b6318b94c9791a74c949428cca05 Mon Sep 17 00:00:00 2001 From: Andrey Knupp Vital Date: Wed, 7 Jan 2015 17:14:59 -0200 Subject: [PATCH 01/11] Prevents prefixing a column when `false` on `column-prefix` (XML) --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 45836a6b9..2ae7be78c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -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; + + $preventPrefixing = ( + $columnPrefix === '0' || $columnPrefix === 'false' + ); + $mapping = array( 'fieldName' => (string) $embeddedMapping['name'], 'class' => (string) $embeddedMapping['class'], - 'columnPrefix' => isset($embeddedMapping['column-prefix']) ? (string) $embeddedMapping['column-prefix'] : null, + 'columnPrefix' => $preventPrefixing ? false : $columnPrefix ); + $metadata->mapEmbedded($mapping); } } From 8bbc4929785091f8ac0a65f6a2cf0edd554ba166 Mon Sep 17 00:00:00 2001 From: Andrey Knupp Vital Date: Wed, 7 Jan 2015 17:24:44 -0200 Subject: [PATCH 02/11] Removing weird strict comparison on different types --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 2ae7be78c..622a79a9e 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -842,6 +842,6 @@ class XmlDriver extends FileDriver { $flag = (string)$element; - return ($flag === true || $flag == "true" || $flag == "1"); + return ($flag == "true" || $flag == "1"); } } From c964dd0cd2c10b13af0f8825086fa96825503a93 Mon Sep 17 00:00:00 2001 From: Andrey Knupp Vital Date: Thu, 8 Jan 2015 00:09:30 -0200 Subject: [PATCH 03/11] Adding `use-column-prefix` attribute as proposed (DDC-3293) #1239 --- doctrine-mapping.xsd | 1 + 1 file changed, 1 insertion(+) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index a6440a2e8..6a7e2a284 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -304,6 +304,7 @@ + From 4935da138d49b46497662798559f7c2b9197e3bd Mon Sep 17 00:00:00 2001 From: Andrey Knupp Vital Date: Thu, 8 Jan 2015 00:10:24 -0200 Subject: [PATCH 04/11] Respecting `use-column-prefix` instead of relying on false/0 of `column-prefix` --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 622a79a9e..a65d4e1ab 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -259,14 +259,16 @@ class XmlDriver extends FileDriver ? (string) $embeddedMapping['column-prefix'] : null; - $preventPrefixing = ( - $columnPrefix === '0' || $columnPrefix === 'false' - ); + $useColumnPrefix = isset($embeddedMapping['use-column-prefix']) + ? $this->evaluateBoolean( + $embeddedMapping['use-column-prefix'] + ) + : true; $mapping = array( 'fieldName' => (string) $embeddedMapping['name'], 'class' => (string) $embeddedMapping['class'], - 'columnPrefix' => $preventPrefixing ? false : $columnPrefix + 'columnPrefix' => !$useColumnPrefix ? false : $columnPrefix ); $metadata->mapEmbedded($mapping); From bacadbf3669c16f27b38d06be8a121e154b50f4d Mon Sep 17 00:00:00 2001 From: Andrey Knupp Vital Date: Thu, 8 Jan 2015 00:11:34 -0200 Subject: [PATCH 05/11] Adding tests for the attribute `use-column-prefix` --- .../Tests/Models/DDC3293/DDC3293Address.php | 10 ++++++++++ .../Tests/Models/DDC3293/DDC3293User.php | 16 ++++++++++++++++ .../Models/DDC3293/DDC3293UserPrefixed.php | 16 ++++++++++++++++ .../ORM/Mapping/XmlMappingDriverTest.php | 19 +++++++++++++++++++ ...ests.Models.DDC3293.DDC3293Address.dcm.xml | 12 ++++++++++++ ...e.Tests.Models.DDC3293.DDC3293User.dcm.xml | 17 +++++++++++++++++ ...Models.DDC3293.DDC3293UserPrefixed.dcm.xml | 17 +++++++++++++++++ 7 files changed, 107 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/DDC3293/DDC3293Address.php create mode 100644 tests/Doctrine/Tests/Models/DDC3293/DDC3293User.php create mode 100644 tests/Doctrine/Tests/Models/DDC3293/DDC3293UserPrefixed.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml diff --git a/tests/Doctrine/Tests/Models/DDC3293/DDC3293Address.php b/tests/Doctrine/Tests/Models/DDC3293/DDC3293Address.php new file mode 100644 index 000000000..70358b74c --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC3293/DDC3293Address.php @@ -0,0 +1,10 @@ +assertEquals(true, $class->isEmbeddedClass); } + public function testEmbeddedUseColumnPrefix() + { + $em = $this->_getTestEntityManager(); + $em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver()); + + $factory = new ClassMetadataFactory(); + $factory->setEntityManager($em); + + $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3293\DDC3293User'); + $this->assertFalse($class->embeddedClasses['address']['columnPrefix']); + + $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3293\DDC3293UserPrefixed'); + + $this->assertEquals( + '__prefix__', + $class->embeddedClasses['address']['columnPrefix'] + ); + } + public function testEmbeddedMapping() { $class = $this->createClassMetadata('Doctrine\Tests\Models\ValueObjects\Person'); diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml new file mode 100644 index 000000000..39c0f33b2 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293Address.dcm.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml new file mode 100644 index 000000000..bf24c1fd6 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293User.dcm.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml new file mode 100644 index 000000000..1e0df304c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC3293.DDC3293UserPrefixed.dcm.xml @@ -0,0 +1,17 @@ + + + + + + + + + From b90943c56b2ee06e14aaea542e6d1d199d0c4b27 Mon Sep 17 00:00:00 2001 From: Andrey Knupp Vital Date: Thu, 8 Jan 2015 09:04:37 -0200 Subject: [PATCH 06/11] Minor improvements --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index a65d4e1ab..21e97c153 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -260,15 +260,13 @@ class XmlDriver extends FileDriver : null; $useColumnPrefix = isset($embeddedMapping['use-column-prefix']) - ? $this->evaluateBoolean( - $embeddedMapping['use-column-prefix'] - ) + ? $this->evaluateBoolean($embeddedMapping['use-column-prefix']) : true; $mapping = array( 'fieldName' => (string) $embeddedMapping['name'], 'class' => (string) $embeddedMapping['class'], - 'columnPrefix' => !$useColumnPrefix ? false : $columnPrefix + 'columnPrefix' => $useColumnPrefix ? $columnPrefix : false ); $metadata->mapEmbedded($mapping); From 08e8af9372b7b37d8e27a89aa960a5045d32c407 Mon Sep 17 00:00:00 2001 From: Andrey Knupp Vital Date: Thu, 8 Jan 2015 09:28:15 -0200 Subject: [PATCH 07/11] Type-hinting `SimpleXMLElement` (_getCascadeMappings) --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 21e97c153..2797fb126 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -790,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 */ From 74a2cfc83b70ad34a895852e98ab560785a13a7b Mon Sep 17 00:00:00 2001 From: Andrey Knupp Vital Date: Thu, 8 Jan 2015 09:37:41 -0200 Subject: [PATCH 08/11] Also adding docs for the new attribute `use-column-prefix` --- docs/en/tutorials/embeddables.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/en/tutorials/embeddables.rst b/docs/en/tutorials/embeddables.rst index cf13fd56e..c5dded1b8 100644 --- a/docs/en/tutorials/embeddables.rst +++ b/docs/en/tutorials/embeddables.rst @@ -141,6 +141,12 @@ directly, set ``columnPrefix=false`` (not yet supported with XML configuration): class: Address columnPrefix: false + .. code-block:: xml + + + + + DQL --- From a701c9d0464e2f36d3bf8a5698bf74c371cf2ab6 Mon Sep 17 00:00:00 2001 From: Andrey Knupp Vital Date: Thu, 8 Jan 2015 10:11:22 -0200 Subject: [PATCH 09/11] Removing warning about non-availability of no-prefix in XML mappings --- docs/en/tutorials/embeddables.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/tutorials/embeddables.rst b/docs/en/tutorials/embeddables.rst index c5dded1b8..be565bf2c 100644 --- a/docs/en/tutorials/embeddables.rst +++ b/docs/en/tutorials/embeddables.rst @@ -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:: From 43db4a41822c5101df480294514b179cda3eba7e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 8 Jan 2015 13:28:11 +0100 Subject: [PATCH 10/11] #1238 DDC-3293 DDC-3477 - adding `@group` annotations for newly introduced tests --- tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 5cebe4f79..2b5cc5bed 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -57,6 +57,11 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest $this->assertEquals(true, $class->isEmbeddedClass); } + /** + * @group DDC-3293 + * @group DDC-3477 + * @group 1238 + */ public function testEmbeddedUseColumnPrefix() { $em = $this->_getTestEntityManager(); From 6fdb1007939367715aeb51d0f766be6fff4fe37c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 8 Jan 2015 13:33:38 +0100 Subject: [PATCH 11/11] #1238 DDC-3293 DDC-3477 - exploding tests with set `use-column-prefix="true"` and `use-column-prefix="false"` xml mappings --- .../ORM/Mapping/XmlMappingDriverTest.php | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 2b5cc5bed..3ca82d08d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -62,22 +62,39 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest * @group DDC-3477 * @group 1238 */ - public function testEmbeddedUseColumnPrefix() + public function testEmbeddedMappingsWithUseColumnPrefix() { - $em = $this->_getTestEntityManager(); - $em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver()); - $factory = new ClassMetadataFactory(); + $em = $this->_getTestEntityManager(); + + $em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver()); $factory->setEntityManager($em); - $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3293\DDC3293User'); - $this->assertFalse($class->embeddedClasses['address']['columnPrefix']); - - $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3293\DDC3293UserPrefixed'); - $this->assertEquals( '__prefix__', - $class->embeddedClasses['address']['columnPrefix'] + $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'] ); }