1
0
mirror of synced 2024-12-14 07:06:04 +03:00

Merge branch 'DDC-631'

This commit is contained in:
Benjamin Eberlei 2010-06-13 23:17:09 +02:00
commit 4705c1cb03
5 changed files with 49 additions and 10 deletions

View File

@ -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'])) {
'columns' => $columns $metadata->table['indexes'][(string)$index['name']] = array(
); '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']);

View File

@ -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,

View File

@ -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,

View File

@ -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>

View File

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