2017-06-07 61 views
0

我使用YML映射学说。我有两个实体。一个Group实体和一个User实体。学说 - 无法坚持实体与复合键

我试图设置它,因此User s在组中具有唯一名称。

我可以创建User,将它分配一个Group,并将其保存到数据库。但是,当我尝试创建User具有相同名称和不同Group时,则出现错误,说明违反了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 

回答

0

我终于想通了这一点。我混淆了教义。

非标准的事情是,我使用大写参数名称来表示对象,并将其更改为表格列的小写字母。我在manyToOne:部分使用了name:

该文档没有真正做到这一点,所以我不知道我仍然需要引用id:部分中的大写属性名称,并在那里单独定义列名称。

于是,我改变了User映射到这一点:

Entity\User: 
    type: entity 
    table: users 
    id: 
     Group: 
      column: group 
      associationKey: true 
      nullable: false 
     name: 
      type: string 
    manyToOne: 
     Group: 
      targetEntity: Entity\Group 
      joinColumn: 
       name: group 
       referencedColumnName: id