我有一个带有文本字段的表格。此字段映射到我的数据库中的一个不可为空的字段(是旧版数据库,我无法更改此字段)
问题在于Symfony2始终将空文本字段设置为NULL
和,这会使插入失败。
有没有办法告诉Symfony2不要将空文本字段设置为NULL
?
首先在实体中默认设置一个空白值
/**
* @ORM\Column(name="example", type="string", length=255, nullable=false)
*/
private $example = '';
对于您的问题,不幸的是,您正在使用Symfony描述一个已知的问题/错误,因此您将不得不覆盖设置为setter函数的值:
public function setExample($example = null) {
if (empty($example)) {
$example = '';
}
$this->example = $example;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句