diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 2e9e944f2..bc0e79e70 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -230,12 +230,21 @@ class XmlDriver extends FileDriver if (isset($xmlRoot->field)) { foreach ($xmlRoot->field as $fieldMapping) { $mapping = $this->columnToArray($fieldMapping); + + if (isset($mapping['version'])) { + $metadata->setVersionMapping($mapping); + } + $metadata->mapField($mapping); } } foreach ($mappings as $mapping) { - $metadata->mapField($mapping); + if (isset($mapping['version'])) { + $metadata->setVersionMapping($mapping); + } + + $metadata->mapField($mapping); } // Evaluate mappings diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index ea53ef28b..35631e7a1 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -297,6 +297,10 @@ class YamlDriver extends FileDriver } } + if (isset($mapping['version'])) { + $metadata->setVersionMapping($mapping); + } + $metadata->mapField($mapping); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index fb8525e6e..b994d4863 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -139,14 +139,25 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase */ public function testFieldMappings($class) { - $this->assertEquals(3, count($class->fieldMappings)); + $this->assertEquals(4, count($class->fieldMappings)); $this->assertTrue(isset($class->fieldMappings['id'])); $this->assertTrue(isset($class->fieldMappings['name'])); $this->assertTrue(isset($class->fieldMappings['email'])); + $this->assertTrue(isset($class->fieldMappings['version'])); return $class; } + /** + * @depends testFieldMappings + * @param ClassMetadata $class + */ + public function testVersionedField($class) + { + $this->assertTrue($class->isVersioned); + $this->assertEquals("version", $class->versionField); + } + /** * @depends testEntityTableNameAndInheritance * @param ClassMetadata $class @@ -793,6 +804,12 @@ class User */ public $groups; + /** + * @Column(type="integer") + * @Version + */ + public $version; + /** * @PrePersist @@ -847,6 +864,9 @@ class User 'columnName' => 'user_email', 'columnDefinition' => 'CHAR(32) NOT NULL', )); + $mapping = array('fieldName' => 'version', 'type' => 'integer'); + $metadata->setVersionMapping($mapping); + $metadata->mapField($mapping); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); $metadata->mapOneToOne(array( 'fieldName' => 'address', diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php index df4dedda5..815523cc1 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php @@ -35,6 +35,9 @@ $metadata->mapField(array( 'columnName' => 'user_email', 'columnDefinition' => 'CHAR(32) NOT NULL', )); +$mapping = array('fieldName' => 'version', 'type' => 'integer'); +$metadata->setVersionMapping($mapping); +$metadata->mapField($mapping); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); $metadata->mapOneToOne(array( 'fieldName' => 'address', @@ -121,4 +124,4 @@ $metadata->setSequenceGeneratorDefinition(array( 'sequenceName' => 'tablename_seq', 'allocationSize' => 100, 'initialValue' => 1, - )); \ No newline at end of file + )); diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml index 18f4d5819..f2ef7d814 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml @@ -4,7 +4,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - + @@ -36,7 +36,7 @@ - + @@ -46,12 +46,14 @@ - + + + - + @@ -60,7 +62,7 @@ - + @@ -74,7 +76,7 @@ - + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml index 5c1018560..3655db20f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml @@ -30,6 +30,9 @@ Doctrine\Tests\ORM\Mapping\User: type: string column: user_email columnDefinition: CHAR(32) NOT NULL + version: + type: integer + version: true oneToOne: address: targetEntity: Address @@ -73,4 +76,4 @@ Doctrine\Tests\ORM\Mapping\User: name_idx: columns: name 0: - columns: user_email \ No newline at end of file + columns: user_email