Skip to content

Commit

Permalink
Merge pull request #254 from jsor/custom_options
Browse files Browse the repository at this point in the history
Pass options attribute in @column annotation to Schema\Column's customSchemaOptions
  • Loading branch information
beberlei committed Jan 15, 2012
2 parents 47e56de + 615e220 commit 27451a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Expand Up @@ -360,6 +360,10 @@ private function _gatherColumn($class, array $mapping, $table)
$options['columnDefinition'] = $mapping['columnDefinition'];
}

if (isset($mapping['options'])) {
$options['customSchemaOptions'] = $mapping['options'];
}

if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == array($mapping['fieldName'])) {
$options['autoincrement'] = true;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php
Expand Up @@ -32,6 +32,21 @@ public function testAddUniqueIndexForUniqueFieldAnnocation()
$this->assertTrue($schema->getTable('cms_users')->columnsAreIndexed(array('username')), "username column should be indexed.");
}

public function testColumnAnnotationOptionsAttribute()
{
$em = $this->_getTestEntityManager();
$schemaTool = new SchemaTool($em);

$classes = array(
$em->getClassMetadata(__NAMESPACE__ . '\\TestEntityWithColumnAnnotationOptionsAttribute'),
);

$schema = $schemaTool->getSchemaFromMetadata($classes);

$expected = array('foo' => 'bar', 'baz' => array('key' => 'val'));
$this->assertEquals($expected, $schema->getTable('TestEntityWithColumnAnnotationOptionsAttribute')->getColumn('test')->getCustomSchemaOptions(), "options annotation are passed to the columns customSchemaOptions");
}

/**
* @group DDC-200
*/
Expand Down Expand Up @@ -86,6 +101,20 @@ public function testPostGenerateEvents()
}
}

/**
* @Entity
*/
class TestEntityWithColumnAnnotationOptionsAttribute
{
/** @Id @Column */
private $id;

/**
* @Column(type="string", options={"foo": "bar", "baz": {"key": "val"}})
*/
private $test;
}

class GenerateSchemaEventListener
{
public $tableCalls = 0;
Expand Down

0 comments on commit 27451a5

Please sign in to comment.