【发布时间】:2014-01-28 06:44:04
【问题描述】:
如何使用注释映射 Doctrine 2 中的单个字符列?我想要一个 char 类型,而不是单个 char 字符串。
【问题讨论】:
标签: orm doctrine-orm annotations char mapping
如何使用注释映射 Doctrine 2 中的单个字符列?我想要一个 char 类型,而不是单个 char 字符串。
【问题讨论】:
标签: orm doctrine-orm annotations char mapping
您始终可以使用带有固定选项的字符串类型:
/**
* @Column(type="string", length=2, options={"fixed" = true})
*/
protected $country;
上面的代码sn-p产生如下SQL:
`country` char(2) NOT NULL,
【讨论】:
Doctrine 没有开箱即用地定义 CHAR 类型,但是它允许您定义自定义类型,您可以使用它来创建用于注释的“char”类型。
Doctrine 文档有一个这样的例子:http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types
【讨论】:
您最终可能会提供自己的完整列定义:
/**
* @Column(type="string", columnDefinition="CHAR(2) NOT NULL")
*/
protected $country = null;
【讨论】: