我将string(32)
而不是integer
用于实体id
字段(它模拟guid类型)。但是从实体ID创建数据库表后,字段类型将设置为varchar(32)
。我认为这不是最好的主意,guid
始终具有length = 32,因此char
类型将更合适。
有没有办法告诉Doctrine使用char
,或者唯一的方法是在数据库中手动更改它?
最佳答案
尽管althaus解决方案很好用,但我认为这应该是规范的解决方法:
带有注释:
/**
* @Column(type="string", length=2, options={"fixed" = true})
*/
protected $country;
使用YAML(ID和非ID字段的示例):
Your\Nice\Entity:
id:
id:
type: string
length: 32
options:
fixed: true
fields:
country:
type: string
length: 2
options:
fixed: true
options:其他选项数组:
fixed
:布尔值,用于确定字符串列的指定长度是固定的还是应变化的(仅适用于字符串/二进制列,可能并非所有供应商都支持)。Official documentation