From 615e22073f5c99200b57b5d755c3cd99fab18f9b Mon Sep 17 00:00:00 2001 From: jsor Date: Wed, 11 Jan 2012 15:58:57 +0100 Subject: [PATCH] Pass options attribute in @Column annotation to Schema\Column's customSchemaOptions --- lib/Doctrine/ORM/Tools/SchemaTool.php | 4 +++ .../Tests/ORM/Tools/SchemaToolTest.php | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 2c1236a1f..2e9feb1f5 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -360,6 +360,10 @@ class SchemaTool $options['columnDefinition'] = $mapping['columnDefinition']; } + if (isset($mapping['options'])) { + $options['customSchemaOptions'] = $mapping['options']; + } + if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == array($mapping['fieldName'])) { $options['autoincrement'] = true; } diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index f38de01b7..6e4b62efe 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -32,6 +32,21 @@ class SchemaToolTest extends \Doctrine\Tests\OrmTestCase $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 */ @@ -86,6 +101,20 @@ class SchemaToolTest extends \Doctrine\Tests\OrmTestCase } } +/** + * @Entity + */ +class TestEntityWithColumnAnnotationOptionsAttribute +{ + /** @Id @Column */ + private $id; + + /** + * @Column(type="string", options={"foo": "bar", "baz": {"key": "val"}}) + */ + private $test; +} + class GenerateSchemaEventListener { public $tableCalls = 0;