diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 09479b77e..4156318ae 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -103,8 +103,11 @@ class AnnotationDriver extends AbstractAnnotationDriver foreach ($tableAnnot->indexes as $indexAnnot) { $index = array( 'columns' => $indexAnnot->columns, - 'flags' => $indexAnnot->flags ); + + if( ! empty($indexAnnot->flags)) { + $index['flags'] = $indexAnnot->flags; + } if ( ! empty($indexAnnot->name)) { $primaryTable['indexes'][$indexAnnot->name] = $index; diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 5bb1e7b51..6a38045cd 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -194,25 +194,21 @@ class XmlDriver extends FileDriver // Evaluate if (isset($xmlRoot->indexes)) { $metadata->table['indexes'] = array(); - foreach ($xmlRoot->indexes->index as $index) { - $columns = explode(',', (string)$index['columns']); + foreach ($xmlRoot->indexes->index as $indexXml) { + $columns = explode(',', (string)$indexXml['columns']); - if( ! isset($index['flags'])) { - $flags = array(); - } else { - $flags = explode(',', (string)$index['flags']); + $index = array( + 'columns' => $columns + ); + + if( isset($indexXml['flags'])) { + $index['flags'] = explode(',', (string)$indexXml['flags']); } - if (isset($index['name'])) { - $metadata->table['indexes'][(string)$index['name']] = array( - 'columns' => $columns, - 'flags' => $flags - ); + if (isset($indexXml['name'])) { + $metadata->table['indexes'][(string)$indexXml['name']] = $index; } else { - $metadata->table['indexes'][] = array( - 'columns' => $columns, - 'flags' => $flags - ); + $metadata->table['indexes'][] = $index; } } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index d0e52c718..2b8a2ce1c 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -201,31 +201,32 @@ class YamlDriver extends FileDriver // Evaluate indexes if (isset($element['indexes'])) { - foreach ($element['indexes'] as $name => $index) { - if ( ! isset($index['name'])) { - $index['name'] = $name; + foreach ($element['indexes'] as $name => $indexYml) { + if ( ! isset($indexYml['name'])) { + $indexYml['name'] = $name; } - if (is_string($index['columns'])) { - $columns = explode(',', $index['columns']); + if (is_string($indexYml['columns'])) { + $columns = explode(',', $indexYml['columns']); $columns = array_map('trim', $columns); } else { - $columns = $index['columns']; + $columns = $indexYml['columns']; } - - if( ! isset($index['flags'])) { - $flags = array(); - } elseif (is_string($index['flags'])) { - $flags = explode(',', $index['flags']); - $flags = array_map('trim', $flags); - } else { - $flags = $index['flags']; - } - - $metadata->table['indexes'][$index['name']] = array( - 'columns' => $columns, - 'flags' => $flags + + $index = array( + 'columns' => $columns ); + + if(isset($indexYml['flags'])) { + if (is_string($indexYml['flags'])) { + $flags = explode(',', $indexYml['flags']); + $index['flags'] = array_map('trim', $flags); + } else { + $index['flags'] = $indexYml['flags']; + } + } + + $metadata->table['indexes'][$indexYml['name']] = $index; } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 49e387e5d..129f7c611 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -73,6 +73,18 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase return $class; } + public function testEntityIndexFlags() + { + $class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Comment'); + + $this->assertEquals(array( + 0 => array( + 'columns' => array('content'), + 'flags' => array('fulltext') + ) + ), $class->table['indexes']); + } + /** * @depends testEntityTableNameAndInheritance * @param ClassMetadata $class @@ -1266,3 +1278,15 @@ class DDC807SubClasse2 {} class Address {} class Phonenumber {} class Group {} + +/** + * @Entity + * @Table(indexes={@Index(columns={"content"}, flags={"fulltext"})}) + */ +class Comment +{ + /** + * @Column(type="text") + */ + private $content; +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php new file mode 100644 index 000000000..a520e0cb1 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.Comment.php @@ -0,0 +1,22 @@ +setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE); +$metadata->setPrimaryTable(array( + 'indexes' => array( + array('columns' => array('content'), 'flags' => array('fulltext')) + ) + )); + + +$metadata->mapField(array( + 'fieldName' => 'content', + 'type' => 'text', + 'scale' => 0, + 'length' => NULL, + 'unique' => false, + 'nullable' => false, + 'precision' => 0, + 'columnName' => 'content', +)); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml new file mode 100644 index 000000000..659ddccd8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Comment.dcm.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Comment.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Comment.dcm.yml new file mode 100644 index 000000000..2186f6a27 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.Comment.dcm.yml @@ -0,0 +1,9 @@ +Doctrine\Tests\ORM\Mapping\Comment: + type: entity + fields: + content: + type: text + indexes: + 0: + columns: content + flags: fulltext