diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 40608d001..fd06dd07c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -118,15 +118,17 @@ class XmlDriver extends AbstractFileDriver // Evaluate if (isset($xmlRoot->{'unique-constraints'})) { foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) { - if (is_string($unique['columns'])) { - $columns = explode(',', $unique['columns']); + $columns = explode(',', (string)$unique['columns']); + + if (isset($unique['name'])) { + $metadata->table['uniqueConstraints'][(string)$unique['name']] = array( + 'columns' => $columns + ); } else { - $columns = $unique['columns']; + $metadata->table['uniqueConstraints'][] = array( + 'columns' => $columns + ); } - - $metadata->table['uniqueConstraints'][$unique['name']] = array( - 'columns' => $columns - ); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 1fdf4a33c..741b35a6c 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -36,6 +36,23 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase return $class; } + /** + * @depends testEntityTableNameAndInheritance + * @param ClassMetadata $class + */ + public function testEntityUniqueConstraints($class) + { + $this->assertArrayHasKey('uniqueConstraints', $class->table, + 'ClassMetadata should have uniqueConstraints key in table property when Unique Constraints are set.'); + + $this->assertEquals(array( + "search_idx" => array("columns" => array("name", "user_email")) + ), $class->table['uniqueConstraints']); + + return $class; + } + + /** * @depends testEntityTableNameAndInheritance * @param ClassMetadata $class @@ -206,7 +223,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase /** * @Entity * @HasLifecycleCallbacks - * @Table(name="cms_users") + * @Table(name="cms_users", uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"})}) */ class User { @@ -369,5 +386,8 @@ class User ), 'orderBy' => NULL, )); + $metadata->table['uniqueConstraints'] = array( + 'search_idx' => array('columns' => array('name', 'user_email')), + ); } } \ No newline at end of file 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 e2a057f14..a7a58c60d 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 @@ -102,4 +102,7 @@ $metadata->mapManyToMany(array( ), ), 'orderBy' => NULL, - )); \ No newline at end of file + )); +$metadata->table['uniqueConstraints'] = array( + 'search_idx' => array('columns' => array('name', 'user_email')), +); \ 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 65b71f04c..7372604bb 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 @@ -6,6 +6,10 @@ http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> + + + + 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 3cf687169..9017da012 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 @@ -51,4 +51,7 @@ Doctrine\Tests\ORM\Mapping\User: - all lifecycleCallbacks: prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ] - postPersist: [ doStuffOnPostPersist ] \ No newline at end of file + postPersist: [ doStuffOnPostPersist ] + uniqueConstraints: + search_idx: + columns: name,user_email \ No newline at end of file