【发布时间】:2014-01-20 20:35:44
【问题描述】:
我在 MySQL 表中有一个列定义如下:
`fuel_type` set('gasoline','diesel','LPG','CNG','ethanol','bio-diesel','hydrogen') DEFAULT NULL,
我使用教义的数据库自省功能生成了实体。有问题的实体中生成的代码是这样的:
/**
* @var simplearray
*
* @ORM\Column(name="fuel_type", type="simplearray", nullable=true)
*/
private $fuelType;
/**
* Set fuelType
*
* @param \simplearray $fuelType
* @return NomEngine
*/
public function setFuelType(\simplearray $fuelType)
{
$this->fuelType = $fuelType;
return $this;
}
/**
* Get fuelType
*
* @return \simplearray
*/
public function getFuelType()
{
return $this->fuelType;
}
在我的奏鸣曲管理类中,configureFormsFields 方法是这样定义的:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name')
->add('fuel_type', 'choice', array(
'choices' => array(
'gasoline' => 'Gasoline',
'diesel' => 'Diesel',
'LPG' => 'LPG',
'CNG' => 'CNG',
'ethanol' => 'Ethanol',
'bio-diesel' => 'Bio Diesel',
'hydrogen' => 'Hydrogen'
),
'multiple' => true,
'required' => false
));
;
}
问题是当我尝试在数据库中保存记录后,我得到了这个异常:
Unknown column type "simplearray" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information.
500 Internal Server Error - DBALException
我尝试了一些方法来解决这个问题:
-
我注意到,生成的类型是“simplearray”,但理论上这种类型是“simple_array”。我以为有错字。 没有成功,我尝试将 simplearray 映射到 config.yml 中的 simple_array :
doctrine: dbal: mapping_types: simplearray: simple_array -
之后,我尝试将实体中的 simplearray 更改为 simple_array。我收到了这个错误:
Catchable Fatal Error: Argument 1 passed to Acme\AdminBundle\Entity\Engine::setFuelType() must be an instance of simple_array, array given, -
我认为管理类传递数组,而实体期待 simple_array,所以我在实体中将 simple_array 更改为数组。 现在错误是这样的:
Could not convert database value "" to Doctrine Type array 500 Internal Server Error - ConversionException
任何有关在 Sonata Admin 中处理集合列的见解将不胜感激!
【问题讨论】: