【发布时间】:2017-06-07 04:46:24
【问题描述】:
我正在使用带有 YML 映射的 Doctrine。我有两个实体。一个Group 实体和一个User 实体。
我正在尝试进行设置,以便 Users 在组内具有唯一名称。
我可以创建一个User,为其分配一个Group,并将其保存到数据库中。但是,当我尝试创建具有相同名称和不同 Group 的 User 时,我收到一条错误消息,指出违反了 name 的唯一约束。
为什么我不能坚持User?
它们的映射如下所示:
Entity\Group:
type: entity
table: groups
id:
id:
type: guid
nullable: false
id: true
generator:
strategy: AUTO
fields:
name:
type: text
nullable: true
Entity\User:
type: entity
table: users
id:
group:
associationKey: true
nullable: false
name:
type: string
manyToOne:
Group:
targetEntity: Entity\Group
joinColumn:
name: group
referencedColumnName: id
【问题讨论】:
标签: symfony doctrine-orm doctrine yaml composite-primary-key