1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Complete custom column option implementation

- Support for xml driver
- Tests
This commit is contained in:
jsor 2012-01-27 11:05:47 +01:00
parent d68fcd8bd2
commit fac820f0e2
6 changed files with 23 additions and 6 deletions

View File

@ -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 File

@ -196,10 +196,6 @@ class XmlDriver extends AbstractFileDriver
$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 @@ class XmlDriver extends AbstractFileDriver
$mapping['columnDefinition'] = (string)$fieldMapping['column-definition'];
}
if (isset($fieldMapping->options)) {
$mapping['options'] = $this->_parseOptions($fieldMapping->options->children());
}
$metadata->mapField($mapping);
}
}

View File

@ -144,6 +144,9 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$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 @@ class User
'unique' => true,
'nullable' => true,
'columnName' => 'name',
'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
));
$metadata->mapField(array(
'fieldName' => 'email',

View File

@ -27,6 +27,7 @@ $metadata->mapField(array(
'unique' => true,
'nullable' => true,
'columnName' => 'name',
'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')),
));
$metadata->mapField(array(
'fieldName' => 'email',

View File

@ -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 File

@ -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