Doctrine orm 如何在yaml原则2中添加约束索引
我有两张用YAML描述的桌子 例如: Entities\User: type: entity table: users id: id: type: integer generator: strategy: AUTO fields: username: type: string length: 64 oneToMany: children: targetEntity: UserToUser mappedBy: parent parents: targetEntity: UserToUser mappedBy: child Entities\UserToUser: type: entity table: user_to_user id: id: type: integer generator: strategy: AUTO fields: user_id: type: integer nullable: false child_id: type: integer nullable: false manyToOne: parent: targetEntity: User inversedBy: children joinColumn: name: user_id referencedColumnName: id child: targetEntity: User inversedBy: parents joinColumn: name: child_id referencedColumnName: id 或其他两种方式: id: user_id: type: integer child_id: type: integer 或 尝试组合这些选项,但由于使用了条令控制台验证,每次都会出现错误,但生成的SQL正是我所需要的 例如,其中之一: 关联父级的联接列必须与源实体Entities\UserToUser的所有标识符列匹配,但是缺少子id 关联子级的联接列必须与源实体Entities\UserToUser的所有标识符列匹配,但是,缺少用户id。Doctrine orm 如何在yaml原则2中添加约束索引,doctrine-orm,yaml,Doctrine Orm,Yaml,我有两张用YAML描述的桌子 例如: Entities\User: type: entity table: users id: id: type: integer generator: strategy: AUTO fields: username: type: string length: 64 oneToMany: children: targetEntity: UserT
我真的不明白我要添加什么,所以验证正确通过了我想这就是您要找的
我想这就是你要找的
在使用YAML时,您可以尝试使用以下符号:
Vendor\CategoryBundle\Entity\Category:
type: entity
table: category
indexes:
# the name of the index
category_slug_idx:
# Columns is an array, specify multiple columns for
# a compound index
columns: [ slug ]
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
slug:
type: string
您可以看到,您可以在index:node下声明索引。在使用YAML时,您可以尝试使用以下符号:
Vendor\CategoryBundle\Entity\Category:
type: entity
table: category
indexes:
# the name of the index
category_slug_idx:
# Columns is an array, specify multiple columns for
# a compound index
columns: [ slug ]
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
slug:
type: string
您可以看到,您可以在index:node下声明索引使用该映射您想要实现什么?您希望每个用户都有一个用户集合吗?还有一个属性是父用户?我想找到一个解决方案,使用YAMLW为2个外键添加唯一索引。您试图通过该映射实现什么?您希望每个用户都有一个用户集合吗?还有一个属性是父用户?我想找到一个解决方案,使用yamlYou为2个外键添加唯一索引。你似乎直接从我作为单独答案发布的要点中复制了我的答案,因此下推为什么不发布答案?你没有回答这个问题,只是发布了一个链接和一个随机yaml模式,它没有回答如何在yaml中添加约束索引的问题。我发布的模式准确地描述了如何为两个外键添加索引,并带有注释。你复制并粘贴了一个对问题不正确的模式,你直接从我的要点上理解了它。我不想推动任何火焰之战,但是,@Pete Michel,你必须记住,stack overflow社区非常清楚,如果你有内容要显示,内容必须在答案中,而不仅仅是链接。始终认为编码者需要在不离开S.O的情况下看到答案。顺便说一句,你在答案中放置的内容与链接中的内容不同。要点中提到了索引键,而答案的正文中没有出现该词。就我个人而言,索引解决了我的问题。我不觉得@perrohunter抄袭了你的答案。你似乎直接抄袭了我作为单独答案发布的要点中的我的答案,因此下推为什么不发布答案?你没有回答这个问题,只是发布了一个链接和一个随机yaml模式,它没有回答如何在yaml中添加约束索引的问题。我发布的模式准确地描述了如何为两个外键添加索引,并带有注释。你复制并粘贴了一个对问题不正确的模式,你直接从我的要点上理解了它。我不想推动任何火焰之战,但是,@Pete Michel,你必须记住,stack overflow社区非常清楚,如果你有内容要显示,内容必须在答案中,而不仅仅是链接。始终认为编码者需要在不离开S.O的情况下看到答案。顺便说一句,你在答案中放置的内容与链接中的内容不同。要点中提到了索引键,而答案的正文中没有出现该词。就我个人而言,索引解决了我的问题。我不觉得@perrohunter抄袭了你的答案。
Vendor\BlogBundle\Entity\BlogImage:
type: entity
table: blog_image
# use two fields for our identifier
id:
blog:
# flag as an association key
associationKey: true
image:
associationKey: true
fields:
caption:
type: string
# Specify our relationships for above
manyToOne:
project:
targetEntity: Vendor\BlogBundle\Entity\Blog
inversedBy: images
oneToOne:
image:
targetEntity: Vendor\ImageBundle\Entity\Image
Vendor\CategoryBundle\Entity\Category:
type: entity
table: category
indexes:
# the name of the index
category_slug_idx:
# Columns is an array, specify multiple columns for
# a compound index
columns: [ slug ]
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
slug:
type: string