1
0
mirror of synced 2024-12-13 14:56:01 +03:00

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:
Benjamin Eberlei 2010-06-13 22:59:56 +02:00
parent 7c2fac64fb
commit 7018509126
5 changed files with 49 additions and 10 deletions

View File

@ -106,21 +106,25 @@ class XmlDriver extends AbstractFileDriver
// Evaluate <indexes...>
if (isset($xmlRoot->indexes)) {
$metadata->table['indexes'] = array();
foreach ($xmlRoot->indexes->index as $index) {
if (is_string($index['columns'])) {
$columns = explode(',', $index['columns']);
} else {
$columns = $index['columns'];
}
$columns = explode(',', (string)$index['columns']);
$metadata->table['indexes'][$index['name']] = array(
'columns' => $columns
);
if (isset($index['name'])) {
$metadata->table['indexes'][(string)$index['name']] = array(
'columns' => $columns
);
} else {
$metadata->table['indexes'][] = array(
'columns' => $columns
);
}
}
}
// Evaluate <unique-constraints..>
if (isset($xmlRoot->{'unique-constraints'})) {
$metadata->table['uniqueConstraints'] = array();
foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) {
$columns = explode(',', (string)$unique['columns']);

View File

@ -36,6 +36,21 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
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
* @param ClassMetadata $class
@ -240,7 +255,11 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
/**
* @Entity
* @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
{
@ -411,6 +430,9 @@ class User
$metadata->table['uniqueConstraints'] = array(
'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(
'sequenceName' => 'tablename_seq',
'allocationSize' => 100,

View File

@ -106,6 +106,9 @@ $metadata->mapManyToMany(array(
$metadata->table['uniqueConstraints'] = array(
'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(
'sequenceName' => 'tablename_seq',
'allocationSize' => 100,

View File

@ -7,6 +7,11 @@
<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-constraint columns="name,user_email" name="search_idx" />
</unique-constraints>

View File

@ -58,4 +58,9 @@ Doctrine\Tests\ORM\Mapping\User:
postPersist: [ doStuffOnPostPersist ]
uniqueConstraints:
search_idx:
columns: name,user_email
columns: name,user_email
indexes:
name_idx:
columns: name
0:
columns: user_email