commit
3a1e24e680
@ -341,6 +341,7 @@
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" type="xs:NMTOKEN" use="optional"/>
|
||||
<xs:attribute name="columns" type="xs:string" use="required"/>
|
||||
<xs:attribute name="flags" type="xs:string" use="optional"/>
|
||||
<xs:anyAttribute namespace="##other"/>
|
||||
</xs:complexType>
|
||||
|
||||
|
@ -102,6 +102,10 @@ class AnnotationDriver extends AbstractAnnotationDriver
|
||||
if ($tableAnnot->indexes !== null) {
|
||||
foreach ($tableAnnot->indexes as $indexAnnot) {
|
||||
$index = array('columns' => $indexAnnot->columns);
|
||||
|
||||
if ( ! empty($indexAnnot->flags)) {
|
||||
$index['flags'] = $indexAnnot->flags;
|
||||
}
|
||||
|
||||
if ( ! empty($indexAnnot->name)) {
|
||||
$primaryTable['indexes'][$indexAnnot->name] = $index;
|
||||
|
@ -194,17 +194,17 @@ class XmlDriver extends FileDriver
|
||||
// Evaluate <indexes...>
|
||||
if (isset($xmlRoot->indexes)) {
|
||||
$metadata->table['indexes'] = array();
|
||||
foreach ($xmlRoot->indexes->index as $index) {
|
||||
$columns = explode(',', (string)$index['columns']);
|
||||
|
||||
if (isset($index['name'])) {
|
||||
$metadata->table['indexes'][(string)$index['name']] = array(
|
||||
'columns' => $columns
|
||||
);
|
||||
foreach ($xmlRoot->indexes->index as $indexXml) {
|
||||
$index = array('columns' => explode(',', (string) $indexXml['columns']));
|
||||
|
||||
if (isset($indexXml['flags'])) {
|
||||
$index['flags'] = explode(',', (string) $indexXml['flags']);
|
||||
}
|
||||
|
||||
if (isset($indexXml['name'])) {
|
||||
$metadata->table['indexes'][(string) $indexXml['name']] = $index;
|
||||
} else {
|
||||
$metadata->table['indexes'][] = array(
|
||||
'columns' => $columns
|
||||
);
|
||||
$metadata->table['indexes'][] = $index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -201,21 +201,26 @@ 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']);
|
||||
$columns = array_map('trim', $columns);
|
||||
if (is_string($indexYml['columns'])) {
|
||||
$index = array('columns' => array_map('trim', explode(',', $indexYml['columns'])));
|
||||
} else {
|
||||
$columns = $index['columns'];
|
||||
$index = array('columns' => $indexYml['columns']);
|
||||
}
|
||||
|
||||
$metadata->table['indexes'][$index['name']] = array(
|
||||
'columns' => $columns
|
||||
);
|
||||
if (isset($indexYml['flags'])) {
|
||||
if (is_string($indexYml['flags'])) {
|
||||
$index['flags'] = array_map('trim', explode(',', $indexYml['flags']));
|
||||
} else {
|
||||
$index['flags'] = $indexYml['flags'];
|
||||
}
|
||||
}
|
||||
|
||||
$metadata->table['indexes'][$indexYml['name']] = $index;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,4 +34,9 @@ final class Index implements Annotation
|
||||
* @var array<string>
|
||||
*/
|
||||
public $columns;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
public $flags;
|
||||
}
|
||||
|
@ -264,7 +264,11 @@ class SchemaTool
|
||||
|
||||
if (isset($class->table['indexes'])) {
|
||||
foreach ($class->table['indexes'] as $indexName => $indexData) {
|
||||
$table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName);
|
||||
if( ! isset($indexData['flags'])) {
|
||||
$indexData['flags'] = array();
|
||||
}
|
||||
|
||||
$table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array)$indexData['flags']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,36 @@ class DDC807SubClasse2 {}
|
||||
class Address {}
|
||||
class Phonenumber {}
|
||||
class Group {}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(indexes={@Index(columns={"content"}, flags={"fulltext"})})
|
||||
*/
|
||||
class Comment
|
||||
{
|
||||
/**
|
||||
* @Column(type="text")
|
||||
*/
|
||||
private $content;
|
||||
|
||||
public static function loadMetadata(ClassMetadataInfo $metadata)
|
||||
{
|
||||
$metadata->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',
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
|
||||
$metadata->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',
|
||||
));
|
@ -0,0 +1,18 @@
|
||||
<?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
|
||||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
<entity name="Doctrine\Tests\ORM\Mapping\Comment">
|
||||
|
||||
<indexes>
|
||||
<index columns="content" flags="fulltext"/>
|
||||
</indexes>
|
||||
|
||||
<field name="content" type="text"/>
|
||||
|
||||
</entity>
|
||||
|
||||
</doctrine-mapping>
|
@ -0,0 +1,9 @@
|
||||
Doctrine\Tests\ORM\Mapping\Comment:
|
||||
type: entity
|
||||
fields:
|
||||
content:
|
||||
type: text
|
||||
indexes:
|
||||
0:
|
||||
columns: content
|
||||
flags: fulltext
|
Loading…
x
Reference in New Issue
Block a user