Skip to content

Commit

Permalink
Complete custom column option implementation
Browse files Browse the repository at this point in the history
- Support for xml driver
- Tests
  • Loading branch information
jsor committed Jan 27, 2012
1 parent d68fcd8 commit fac820f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions doctrine-mapping.xsd
Expand Up @@ -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" />
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
Expand Up @@ -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;
}
Expand All @@ -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);
}
}
Expand Down
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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',
Expand Down
Expand Up @@ -27,6 +27,7 @@
'unique' => true,
'nullable' => true,
'columnName' => 'name',
'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
));
$metadata->mapField(array(
'fieldName' => 'email',
Expand Down
Expand Up @@ -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">
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit fac820f

Please sign in to comment.