[DDC-1617] Implement support for Generating Unique Constraints/Indexes in @Table annotation of EntityGenerator.
This commit is contained in:
parent
35fc3c0671
commit
551df4af52
@ -583,9 +583,32 @@ public function <methodName>()
|
||||
$table[] = 'name="' . $metadata->table['name'] . '"';
|
||||
}
|
||||
|
||||
if (isset($metadata->table['uniqueConstraints']) && $metadata->table['uniqueConstraints']) {
|
||||
$constraints = $this->_generateTableConstraints('UniqueConstraint', $metadata->table['uniqueConstraints']);
|
||||
$table[] = 'uniqueConstraints={' . $constraints . '}';
|
||||
}
|
||||
|
||||
if (isset($metadata->table['indexes']) && $metadata->table['indexes']) {
|
||||
$constraints = $this->_generateTableConstraints('Index', $metadata->table['indexes']);
|
||||
$table[] = 'indexes={' . $constraints . '}';
|
||||
}
|
||||
|
||||
return '@' . $this->_annotationsPrefix . 'Table(' . implode(', ', $table) . ')';
|
||||
}
|
||||
|
||||
private function _generateTableConstraints($constraintName, $constraints)
|
||||
{
|
||||
$annotations = array();
|
||||
foreach ($constraints as $name => $constraint) {
|
||||
$columns = array();
|
||||
foreach ($constraint['columns'] as $column) {
|
||||
$columns[] = '"' . $column . '"';
|
||||
}
|
||||
$annotations[] = '@' . $this->_annotationsPrefix . $constraintName . '(name="' . $name . '", columns={' . implode(', ', $columns) . '})';
|
||||
}
|
||||
return implode(', ', $annotations);
|
||||
}
|
||||
|
||||
private function _generateInheritanceAnnotation($metadata)
|
||||
{
|
||||
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
|
||||
|
@ -47,6 +47,8 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
$metadata->customRepositoryClassName = $this->_namespace . '\EntityGeneratorBookRepository';
|
||||
|
||||
$metadata->table['name'] = 'book';
|
||||
$metadata->table['uniqueConstraints']['name_uniq'] = array('columns' => array('name'));
|
||||
$metadata->table['indexes']['status_idx'] = array('columns' => array('status'));
|
||||
$metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
|
||||
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'default' => 'published'));
|
||||
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
|
||||
|
Loading…
Reference in New Issue
Block a user