fix default field type
This commit is contained in:
parent
81cc6d9da8
commit
0632b37492
@ -166,9 +166,12 @@ class XmlDriver extends AbstractFileDriver
|
||||
foreach ($xmlRoot->field as $fieldMapping) {
|
||||
$mapping = array(
|
||||
'fieldName' => (string)$fieldMapping['name'],
|
||||
'type' => (string)$fieldMapping['type']
|
||||
);
|
||||
|
||||
if (isset($fieldMapping['type'])) {
|
||||
$mapping['type'] = (string)$fieldMapping['type'];
|
||||
}
|
||||
|
||||
if (isset($fieldMapping['column'])) {
|
||||
$mapping['columnName'] = (string)$fieldMapping['column'];
|
||||
}
|
||||
@ -219,10 +222,13 @@ class XmlDriver extends AbstractFileDriver
|
||||
|
||||
$mapping = array(
|
||||
'id' => true,
|
||||
'fieldName' => (string)$idElement['name'],
|
||||
'type' => (string)$idElement['type']
|
||||
'fieldName' => (string)$idElement['name']
|
||||
);
|
||||
|
||||
if (isset($fieldMapping['type'])) {
|
||||
$mapping['type'] = (string)$idElement['type'];
|
||||
}
|
||||
|
||||
if (isset($idElement['column'])) {
|
||||
$mapping['columnName'] = (string)$idElement['column'];
|
||||
}
|
||||
|
@ -165,16 +165,15 @@ class YamlDriver extends AbstractFileDriver
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($idElement['type'])) {
|
||||
throw MappingException::propertyTypeIsRequired($className, $name);
|
||||
}
|
||||
|
||||
$mapping = array(
|
||||
'id' => true,
|
||||
'fieldName' => $name,
|
||||
'type' => $idElement['type']
|
||||
'fieldName' => $name
|
||||
);
|
||||
|
||||
if (isset($idElement['type'])) {
|
||||
$mapping['type'] = $idElement['type'];
|
||||
}
|
||||
|
||||
if (isset($idElement['column'])) {
|
||||
$mapping['columnName'] = $idElement['column'];
|
||||
}
|
||||
@ -201,19 +200,21 @@ class YamlDriver extends AbstractFileDriver
|
||||
// Evaluate fields
|
||||
if (isset($element['fields'])) {
|
||||
foreach ($element['fields'] as $name => $fieldMapping) {
|
||||
if (!isset($fieldMapping['type'])) {
|
||||
throw MappingException::propertyTypeIsRequired($className, $name);
|
||||
|
||||
$mapping = array(
|
||||
'fieldName' => $name
|
||||
);
|
||||
|
||||
if (isset($fieldMapping['type'])) {
|
||||
$e = explode('(', $fieldMapping['type']);
|
||||
$fieldMapping['type'] = $e[0];
|
||||
$mapping['type'] = $fieldMapping['type'];
|
||||
|
||||
if (isset($e[1])) {
|
||||
$fieldMapping['length'] = substr($e[1], 0, strlen($e[1]) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
$e = explode('(', $fieldMapping['type']);
|
||||
$fieldMapping['type'] = $e[0];
|
||||
if (isset($e[1])) {
|
||||
$fieldMapping['length'] = substr($e[1], 0, strlen($e[1]) - 1);
|
||||
}
|
||||
$mapping = array(
|
||||
'fieldName' => $name,
|
||||
'type' => $fieldMapping['type']
|
||||
);
|
||||
if (isset($fieldMapping['id'])) {
|
||||
$mapping['id'] = true;
|
||||
if (isset($fieldMapping['generator']['strategy'])) {
|
||||
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC1476;
|
||||
|
||||
/**
|
||||
* @Entity()
|
||||
*/
|
||||
class DDC1476EntityWithDefaultFieldType
|
||||
{
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @Column()
|
||||
* @GeneratedValue("NONE")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/** @column() */
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
|
||||
{
|
||||
$metadata->mapField(array(
|
||||
'id' => true,
|
||||
'fieldName' => 'id',
|
||||
));
|
||||
$metadata->mapField(array(
|
||||
'fieldName' => 'name',
|
||||
));
|
||||
|
||||
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_NONE);
|
||||
}
|
||||
|
||||
}
|
@ -327,6 +327,51 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
$em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment"));
|
||||
$this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1476
|
||||
*/
|
||||
public function testDefaultFieldType()
|
||||
{
|
||||
$driver = $this->_loadDriver();
|
||||
$em = $this->_getTestEntityManager();
|
||||
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
|
||||
|
||||
$em->getConfiguration()->setMetadataDriverImpl($driver);
|
||||
$factory->setEntityManager($em);
|
||||
|
||||
|
||||
$class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
|
||||
|
||||
|
||||
$this->assertArrayHasKey('id', $class->fieldMappings);
|
||||
$this->assertArrayHasKey('name', $class->fieldMappings);
|
||||
|
||||
|
||||
$this->assertArrayHasKey('type', $class->fieldMappings['id']);
|
||||
$this->assertArrayHasKey('type', $class->fieldMappings['name']);
|
||||
|
||||
$this->assertEquals('string', $class->fieldMappings['id']['type']);
|
||||
$this->assertEquals('string', $class->fieldMappings['name']['type']);
|
||||
|
||||
|
||||
|
||||
$this->assertArrayHasKey('fieldName', $class->fieldMappings['id']);
|
||||
$this->assertArrayHasKey('fieldName', $class->fieldMappings['name']);
|
||||
|
||||
$this->assertEquals('id', $class->fieldMappings['id']['fieldName']);
|
||||
$this->assertEquals('name', $class->fieldMappings['name']['fieldName']);
|
||||
|
||||
|
||||
|
||||
$this->assertArrayHasKey('columnName', $class->fieldMappings['id']);
|
||||
$this->assertArrayHasKey('columnName', $class->fieldMappings['name']);
|
||||
|
||||
$this->assertEquals('id', $class->fieldMappings['id']['columnName']);
|
||||
$this->assertEquals('name', $class->fieldMappings['name']['columnName']);
|
||||
|
||||
$this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $class->generatorType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
|
||||
$metadata->mapField(array(
|
||||
'id' => true,
|
||||
'fieldName' => 'id',
|
||||
));
|
||||
$metadata->mapField(array(
|
||||
'fieldName' => 'name'
|
||||
));
|
||||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
|
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
<entity name="Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType">
|
||||
<id name="id">
|
||||
<generator strategy="NONE"/>
|
||||
</id>
|
||||
|
||||
<field name="name"/>
|
||||
</entity>
|
||||
|
||||
</doctrine-mapping>
|
@ -0,0 +1,8 @@
|
||||
Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType:
|
||||
type: entity
|
||||
id:
|
||||
id:
|
||||
generator:
|
||||
strategy: NONE
|
||||
fields:
|
||||
name:
|
Loading…
Reference in New Issue
Block a user