Skip to content
Browse files

Complete custom column option implementation

- Support for xml driver
- Tests
  • Loading branch information...
1 parent d68fcd8 commit fac820f0e29d3dbfb185d27bd9816066b0a2dc10 @jsor jsor committed Jan 27, 2012
View
1 doctrine-mapping.xsd
@@ -182,6 +182,7 @@
<xs:complexType name="field">
<xs:sequence>
+ <xs:element name="options" type="orm:options" minOccurs="0" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
View
8 lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
@@ -196,10 +196,6 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
$mapping['unique'] = ((string)$fieldMapping['unique'] == "false") ? false : true;
}
- if (isset($fieldMapping['options'])) {
- $mapping['options'] = (array)$fieldMapping['options'];
- }
-
if (isset($fieldMapping['nullable'])) {
$mapping['nullable'] = ((string)$fieldMapping['nullable'] == "false") ? false : true;
}
@@ -212,6 +208,10 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
$mapping['columnDefinition'] = (string)$fieldMapping['column-definition'];
}
+ if (isset($fieldMapping->options)) {
+ $mapping['options'] = $this->_parseOptions($fieldMapping->options->children());
+ }
+
$metadata->mapField($mapping);
}
}
View
6 tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php
@@ -144,6 +144,9 @@ public function testStringFieldMappings($class)
$this->assertTrue($class->fieldMappings['name']['nullable']);
$this->assertTrue($class->fieldMappings['name']['unique']);
+ $expected = array('foo' => 'bar', 'baz' => array('key' => 'val'));
+ $this->assertEquals($expected, $class->fieldMappings['name']['options']);
+
return $class;
}
@@ -454,7 +457,7 @@ class User
public $id;
/**
- * @Column(length=50, nullable=true, unique=true)
+ * @Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}})
*/
public $name;
@@ -530,6 +533,7 @@ public static function loadMetadata(ClassMetadataInfo $metadata)
'unique' => true,
'nullable' => true,
'columnName' => 'name',
+ 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
));
$metadata->mapField(array(
'fieldName' => 'email',
View
1 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php
@@ -27,6 +27,7 @@
'unique' => true,
'nullable' => true,
'columnName' => 'name',
+ 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
));
$metadata->mapField(array(
'fieldName' => 'email',
View
9 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml
@@ -37,7 +37,14 @@
<sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" />
</id>
- <field name="name" column="name" type="string" length="50" nullable="true" unique="true" />
+ <field name="name" column="name" type="string" length="50" nullable="true" unique="true">
+ <options>
+ <option name="foo">bar</option>
+ <option name="baz">
+ <option name="key">val</option>
+ </option>
+ </options>
+ </field>
<field name="email" column="user_email" type="string" column-definition="CHAR(32) NOT NULL" />
<one-to-one field="address" target-entity="Address" inversed-by="user">
View
4 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml
@@ -22,6 +22,10 @@ Doctrine\Tests\ORM\Mapping\User:
length: 50
nullable: true
unique: true
+ options:
+ foo: bar
+ baz:
+ key: val
email:
type: string
column: user_email

0 comments on commit fac820f

Please sign in to comment.
Something went wrong with that request. Please try again.