Refactor partial into options array
This coherent with what is done for Table. All platform specific things are grouped into an options array. Eventually flags should be migrated into options as well.
This commit is contained in:
parent
eeb7ff4a6d
commit
27adf8d6e9
@ -320,11 +320,11 @@
|
||||
|
||||
<xs:complexType name="unique-constraint">
|
||||
<xs:sequence>
|
||||
<xs:element name="options" type="orm:options" minOccurs="0" />
|
||||
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" type="xs:NMTOKEN" use="optional"/>
|
||||
<xs:attribute name="columns" type="xs:string" use="required"/>
|
||||
<xs:attribute name="where" type="xs:string" use="optional"/>
|
||||
<xs:anyAttribute namespace="##other"/>
|
||||
</xs:complexType>
|
||||
|
||||
@ -338,12 +338,12 @@
|
||||
|
||||
<xs:complexType name="index">
|
||||
<xs:sequence>
|
||||
<xs:element name="options" type="orm:options" minOccurs="0" />
|
||||
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
|
||||
</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:attribute name="where" type="xs:string" use="optional"/>
|
||||
<xs:anyAttribute namespace="##other"/>
|
||||
</xs:complexType>
|
||||
|
||||
|
@ -107,8 +107,8 @@ class AnnotationDriver extends AbstractAnnotationDriver
|
||||
$index['flags'] = $indexAnnot->flags;
|
||||
}
|
||||
|
||||
if (! empty($indexAnnot->where)) {
|
||||
$index['where'] = $indexAnnot->where;
|
||||
if (! empty($indexAnnot->options)) {
|
||||
$index['options'] = $indexAnnot->options;
|
||||
}
|
||||
|
||||
if ( ! empty($indexAnnot->name)) {
|
||||
@ -122,9 +122,9 @@ class AnnotationDriver extends AbstractAnnotationDriver
|
||||
if ($tableAnnot->uniqueConstraints !== null) {
|
||||
foreach ($tableAnnot->uniqueConstraints as $uniqueConstraintAnnot) {
|
||||
$uniqueConstraint = array('columns' => $uniqueConstraintAnnot->columns);
|
||||
|
||||
if ( ! empty($uniqueConstraintAnnot->where)) {
|
||||
$uniqueConstraint['where'] = $uniqueConstraintAnnot->where;
|
||||
|
||||
if ( ! empty($uniqueConstraintAnnot->options)) {
|
||||
$uniqueConstraint['options'] = $uniqueConstraintAnnot->options;
|
||||
}
|
||||
|
||||
if ( ! empty($uniqueConstraintAnnot->name)) {
|
||||
|
@ -201,8 +201,8 @@ class XmlDriver extends FileDriver
|
||||
$index['flags'] = explode(',', (string) $indexXml['flags']);
|
||||
}
|
||||
|
||||
if (isset($indexXml['where'])) {
|
||||
$index['where'] = $indexXml['where'];
|
||||
if (isset($indexXml->options)) {
|
||||
$index['options'] = $this->_parseOptions($indexXml->options->children());
|
||||
}
|
||||
|
||||
if (isset($indexXml['name'])) {
|
||||
@ -219,8 +219,9 @@ class XmlDriver extends FileDriver
|
||||
foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $uniqueXml) {
|
||||
$unique = array('columns' => explode(',', (string) $uniqueXml['columns']));
|
||||
|
||||
if (isset($uniqueXml['where'])) {
|
||||
$unique['where'] = $uniqueXml['where'];
|
||||
|
||||
if (isset($uniqueXml->options)) {
|
||||
$unique['options'] = $this->_parseOptions($uniqueXml->options->children());
|
||||
}
|
||||
|
||||
if (isset($uniqueXml['name'])) {
|
||||
|
@ -220,8 +220,8 @@ class YamlDriver extends FileDriver
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($indexYml['where'])) {
|
||||
$index['where'] = $indexYml['where'];
|
||||
if (isset($indexYml['options'])) {
|
||||
$index['options'] = $indexYml['options'];
|
||||
}
|
||||
|
||||
$metadata->table['indexes'][$indexYml['name']] = $index;
|
||||
@ -241,8 +241,8 @@ class YamlDriver extends FileDriver
|
||||
$unique = array('columns' => $uniqueYml['columns']);
|
||||
}
|
||||
|
||||
if (isset($uniqueYml['where'])) {
|
||||
$unique['where'] = $uniqueYml['where'];
|
||||
if (isset($uniqueYml['options'])) {
|
||||
$unique['options'] = $uniqueYml['options'];
|
||||
}
|
||||
|
||||
$metadata->table['uniqueConstraints'][$uniqueYml['name']] = $unique;
|
||||
|
@ -41,7 +41,7 @@ final class Index implements Annotation
|
||||
public $flags;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var array
|
||||
*/
|
||||
public $where;
|
||||
public $options;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ final class UniqueConstraint implements Annotation
|
||||
public $columns;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var array
|
||||
*/
|
||||
public $where;
|
||||
public $options;
|
||||
}
|
||||
|
@ -268,13 +268,13 @@ class SchemaTool
|
||||
$indexData['flags'] = array();
|
||||
}
|
||||
|
||||
$table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array)$indexData['flags'], isset($indexData['where']) ? $indexData['where'] : null);
|
||||
$table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array)$indexData['flags'], isset($indexData['options']) ? $indexData['options'] : array());
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($class->table['uniqueConstraints'])) {
|
||||
foreach ($class->table['uniqueConstraints'] as $indexName => $indexData) {
|
||||
$table->addUniqueIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, isset($indexData['where']) ? $indexData['where'] : null);
|
||||
$table->addUniqueIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, isset($indexData['options']) ? $indexData['options'] : array());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
0 => array(
|
||||
'columns' => array('content'),
|
||||
'flags' => array('fulltext'),
|
||||
'where' => 'content IS NOT NULL',
|
||||
'options' => array('where' => 'content IS NOT NULL'),
|
||||
)
|
||||
), $class->table['indexes']);
|
||||
}
|
||||
@ -96,7 +96,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
'ClassMetadata should have uniqueConstraints key in table property when Unique Constraints are set.');
|
||||
|
||||
$this->assertEquals(array(
|
||||
"search_idx" => array("columns" => array("name", "user_email"), 'where' => 'name IS NOT NULL')
|
||||
"search_idx" => array("columns" => array("name", "user_email"), 'options' => array('where' => 'name IS NOT NULL'))
|
||||
), $class->table['uniqueConstraints']);
|
||||
|
||||
return $class;
|
||||
@ -939,7 +939,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
* @HasLifecycleCallbacks
|
||||
* @Table(
|
||||
* name="cms_users",
|
||||
* uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"}, where="name IS NOT NULL")},
|
||||
* uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"}, options={"where": "name IS NOT NULL"})},
|
||||
* indexes={@Index(name="name_idx", columns={"name"}), @Index(name="0", columns={"user_email"})},
|
||||
* options={"foo": "bar", "baz": {"key": "val"}}
|
||||
* )
|
||||
@ -1123,7 +1123,7 @@ class User
|
||||
'orderBy' => NULL,
|
||||
));
|
||||
$metadata->table['uniqueConstraints'] = array(
|
||||
'search_idx' => array('columns' => array('name', 'user_email'), 'where' => 'name IS NOT NULL'),
|
||||
'search_idx' => array('columns' => array('name', 'user_email'), 'options'=> array('where' => 'name IS NOT NULL')),
|
||||
);
|
||||
$metadata->table['indexes'] = array(
|
||||
'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
|
||||
@ -1282,7 +1282,7 @@ class Group {}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(indexes={@Index(columns={"content"}, flags={"fulltext"}, where="content IS NOT NULL")})
|
||||
* @Table(indexes={@Index(columns={"content"}, flags={"fulltext"}, options={"where": "content IS NOT NULL"})})
|
||||
*/
|
||||
class Comment
|
||||
{
|
||||
@ -1296,7 +1296,7 @@ class Comment
|
||||
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
|
||||
$metadata->setPrimaryTable(array(
|
||||
'indexes' => array(
|
||||
array('columns' => array('content'), 'flags' => array('fulltext'), 'where' => 'content IS NOT NULL')
|
||||
array('columns' => array('content'), 'flags' => array('fulltext'), 'options' => array('where' => 'content IS NOT NULL'))
|
||||
)
|
||||
));
|
||||
|
||||
|
@ -5,7 +5,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
|
||||
$metadata->setPrimaryTable(array(
|
||||
'indexes' => array(
|
||||
array('columns' => array('content'), 'flags' => array('fulltext'), 'where' => 'content IS NOT NULL')
|
||||
array('columns' => array('content'), 'flags' => array('fulltext'), 'options'=> array('where' => 'content IS NOT NULL'))
|
||||
)
|
||||
));
|
||||
|
||||
|
@ -116,7 +116,7 @@ $metadata->table['options'] = array(
|
||||
'baz' => array('key' => 'val')
|
||||
);
|
||||
$metadata->table['uniqueConstraints'] = array(
|
||||
'search_idx' => array('columns' => array('name', 'user_email'), 'where' => 'name IS NOT NULL'),
|
||||
'search_idx' => array('columns' => array('name', 'user_email'), 'options' => array('where' => 'name IS NOT NULL')),
|
||||
);
|
||||
$metadata->table['indexes'] = array(
|
||||
'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
|
||||
|
@ -8,7 +8,11 @@
|
||||
<entity name="Doctrine\Tests\ORM\Mapping\Comment">
|
||||
|
||||
<indexes>
|
||||
<index columns="content" flags="fulltext" where="content IS NOT NULL"/>
|
||||
<index columns="content" flags="fulltext">
|
||||
<options>
|
||||
<option name="where">content IS NOT NULL</option>
|
||||
</options>
|
||||
</index>
|
||||
</indexes>
|
||||
|
||||
<field name="content" type="text"/>
|
||||
|
@ -19,7 +19,11 @@
|
||||
</indexes>
|
||||
|
||||
<unique-constraints>
|
||||
<unique-constraint columns="name,user_email" name="search_idx" where="name IS NOT NULL" />
|
||||
<unique-constraint columns="name,user_email" name="search_idx">
|
||||
<options>
|
||||
<option name="where">name IS NOT NULL</option>
|
||||
</options>
|
||||
</unique-constraint>
|
||||
</unique-constraints>
|
||||
|
||||
<lifecycle-callbacks>
|
||||
|
@ -7,4 +7,5 @@ Doctrine\Tests\ORM\Mapping\Comment:
|
||||
0:
|
||||
columns: content
|
||||
flags: fulltext
|
||||
where: "content IS NOT NULL"
|
||||
options:
|
||||
where: "content IS NOT NULL"
|
||||
|
@ -74,7 +74,8 @@ Doctrine\Tests\ORM\Mapping\User:
|
||||
uniqueConstraints:
|
||||
search_idx:
|
||||
columns: name,user_email
|
||||
where: name IS NOT NULL
|
||||
options:
|
||||
where: name IS NOT NULL
|
||||
indexes:
|
||||
name_idx:
|
||||
columns: name
|
||||
|
Loading…
Reference in New Issue
Block a user