Fix a bug with Table Indexes on XML Driver. Added tests for setting indexes on tables for all the mapping drivers
This commit is contained in:
parent
7c2fac64fb
commit
7018509126
@ -106,21 +106,25 @@ class XmlDriver extends AbstractFileDriver
|
|||||||
|
|
||||||
// Evaluate <indexes...>
|
// Evaluate <indexes...>
|
||||||
if (isset($xmlRoot->indexes)) {
|
if (isset($xmlRoot->indexes)) {
|
||||||
|
$metadata->table['indexes'] = array();
|
||||||
foreach ($xmlRoot->indexes->index as $index) {
|
foreach ($xmlRoot->indexes->index as $index) {
|
||||||
if (is_string($index['columns'])) {
|
$columns = explode(',', (string)$index['columns']);
|
||||||
$columns = explode(',', $index['columns']);
|
|
||||||
} else {
|
|
||||||
$columns = $index['columns'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$metadata->table['indexes'][$index['name']] = array(
|
if (isset($index['name'])) {
|
||||||
|
$metadata->table['indexes'][(string)$index['name']] = array(
|
||||||
'columns' => $columns
|
'columns' => $columns
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$metadata->table['indexes'][] = array(
|
||||||
|
'columns' => $columns
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate <unique-constraints..>
|
// Evaluate <unique-constraints..>
|
||||||
if (isset($xmlRoot->{'unique-constraints'})) {
|
if (isset($xmlRoot->{'unique-constraints'})) {
|
||||||
|
$metadata->table['uniqueConstraints'] = array();
|
||||||
foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) {
|
foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) {
|
||||||
$columns = explode(',', (string)$unique['columns']);
|
$columns = explode(',', (string)$unique['columns']);
|
||||||
|
|
||||||
|
@ -36,6 +36,21 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
return $class;
|
return $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testEntityTableNameAndInheritance
|
||||||
|
* @param ClassMetadata $class
|
||||||
|
*/
|
||||||
|
public function testEntityIndexes($class)
|
||||||
|
{
|
||||||
|
$this->assertArrayHasKey('indexes', $class->table, 'ClassMetadata should have indexes key in table property.');
|
||||||
|
$this->assertEquals(array(
|
||||||
|
'name_idx' => array('columns' => array('name')),
|
||||||
|
0 => array('columns' => array('user_email'))
|
||||||
|
), $class->table['indexes']);
|
||||||
|
|
||||||
|
return $class;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testEntityTableNameAndInheritance
|
* @depends testEntityTableNameAndInheritance
|
||||||
* @param ClassMetadata $class
|
* @param ClassMetadata $class
|
||||||
@ -240,7 +255,11 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
/**
|
/**
|
||||||
* @Entity
|
* @Entity
|
||||||
* @HasLifecycleCallbacks
|
* @HasLifecycleCallbacks
|
||||||
* @Table(name="cms_users", uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"})})
|
* @Table(
|
||||||
|
* name="cms_users",
|
||||||
|
* uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"})},
|
||||||
|
* indexes={@Index(name="name_idx", columns={"name"}), @Index(name="0", columns={"user_email"})}
|
||||||
|
* )
|
||||||
*/
|
*/
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
@ -411,6 +430,9 @@ class User
|
|||||||
$metadata->table['uniqueConstraints'] = array(
|
$metadata->table['uniqueConstraints'] = array(
|
||||||
'search_idx' => array('columns' => array('name', 'user_email')),
|
'search_idx' => array('columns' => array('name', 'user_email')),
|
||||||
);
|
);
|
||||||
|
$metadata->table['indexes'] = array(
|
||||||
|
'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
|
||||||
|
);
|
||||||
$metadata->setSequenceGeneratorDefinition(array(
|
$metadata->setSequenceGeneratorDefinition(array(
|
||||||
'sequenceName' => 'tablename_seq',
|
'sequenceName' => 'tablename_seq',
|
||||||
'allocationSize' => 100,
|
'allocationSize' => 100,
|
||||||
|
@ -106,6 +106,9 @@ $metadata->mapManyToMany(array(
|
|||||||
$metadata->table['uniqueConstraints'] = array(
|
$metadata->table['uniqueConstraints'] = array(
|
||||||
'search_idx' => array('columns' => array('name', 'user_email')),
|
'search_idx' => array('columns' => array('name', 'user_email')),
|
||||||
);
|
);
|
||||||
|
$metadata->table['indexes'] = array(
|
||||||
|
'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
|
||||||
|
);
|
||||||
$metadata->setSequenceGeneratorDefinition(array(
|
$metadata->setSequenceGeneratorDefinition(array(
|
||||||
'sequenceName' => 'tablename_seq',
|
'sequenceName' => 'tablename_seq',
|
||||||
'allocationSize' => 100,
|
'allocationSize' => 100,
|
||||||
|
@ -7,6 +7,11 @@
|
|||||||
|
|
||||||
<entity name="Doctrine\Tests\ORM\Mapping\User" table="cms_users">
|
<entity name="Doctrine\Tests\ORM\Mapping\User" table="cms_users">
|
||||||
|
|
||||||
|
<indexes>
|
||||||
|
<index name="name_idx" columns="name"/>
|
||||||
|
<index columns="user_email"/>
|
||||||
|
</indexes>
|
||||||
|
|
||||||
<unique-constraints>
|
<unique-constraints>
|
||||||
<unique-constraint columns="name,user_email" name="search_idx" />
|
<unique-constraint columns="name,user_email" name="search_idx" />
|
||||||
</unique-constraints>
|
</unique-constraints>
|
||||||
|
@ -59,3 +59,8 @@ Doctrine\Tests\ORM\Mapping\User:
|
|||||||
uniqueConstraints:
|
uniqueConstraints:
|
||||||
search_idx:
|
search_idx:
|
||||||
columns: name,user_email
|
columns: name,user_email
|
||||||
|
indexes:
|
||||||
|
name_idx:
|
||||||
|
columns: name
|
||||||
|
0:
|
||||||
|
columns: user_email
|
Loading…
Reference in New Issue
Block a user