-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,28 @@ public function testNullDefaultNotAddedToCustomSchemaOptions() | |
|
||
$this->assertSame(array(), $customSchemaOptions); | ||
} | ||
|
||
/** | ||
* @group DDC-3671 | ||
*/ | ||
public function testSchemaHasProperIndexesFromUniqueConstraintAnnotation() | ||
{ | ||
$em = $this->_getTestEntityManager(); | ||
$schemaTool = new SchemaTool($em); | ||
|
||
$classes = [ | ||
$em->getClassMetadata(__NAMESPACE__ . '\\UniqueConstraintAnnotationModel'), | ||
]; | ||
|
||
$schema = $schemaTool->getSchemaFromMetadata($classes); | ||
|
||
$this->assertTrue($schema->hasTable('unique_constraint_annotation_table')); | ||
$table = $schema->getTable('unique_constraint_annotation_table'); | ||
|
||
$this->assertEquals(2, count($table->getIndexes())); | ||
$this->assertTrue($table->hasIndex('primary')); | ||
$this->assertTrue($table->hasIndex('uniq_hash')); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -148,3 +170,20 @@ public function postGenerateSchema(GenerateSchemaEventArgs $eventArgs) | |
$this->schemaCalled = true; | ||
} | ||
} | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="unique_constraint_annotation_table", uniqueConstraints={ | ||
* @UniqueConstraint(name="uniq_hash", columns={"hash"}) | ||
* }) | ||
*/ | ||
class UniqueConstraintAnnotationModel | ||
{ | ||
/** @Id @Column */ | ||
private $id; | ||
|
||
/** | ||
* @Column(name="hash", type="string", length=8, nullable=false, unique=true) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Ocramius
Member
|
||
*/ | ||
private $hash; | ||
} |
This mapping really makes no sense to me. You are explicitly defining 2 unique indexes here. One via table's
UniqueConstraint
annotation and one via column'sunique
attribute.IMO one should define one of them but not both. Silently dropping the duplicate index then has evil side effects. See doctrine/dbal#2248
I am still of the opinion that Doctrine should be as transparent as possible about index creation and only do "magic" where completely necessary. In the end it's the user's responsibility to take care of definitions and without Doctrine putting a lot of magic in there, it's also much better comprehensible what the mappings are actually doing.
IMO this commit has to be reverted. /cc @Ocramius @zeroedin-bill