Doctrine 1 和 Symfony 1 的多个主键?

2024-05-18

我已经知道在 Symfony 1 和 Doctrine 1 中不可能使用多个主键,但是你们知道有什么好的解决方法吗?


除了多对多关系之外,原则 1 不适用于多列上的主键。但如果你想使用多对多关系,请像这样使用:

BlogPost:
  columns:
    user_id: integer
    title: string(255)
    body: clob
  relations:
    User:
      local: user_id
      foreign: id
      type: one
      foreignType: one
      foreignAlias: BlogPosts
    Tags:
      class: Tag
      foreignAlias: BlogPosts
      refClass: BlogPostTag
      local: blog_post_id
      foreign: tag_id

Tag:
  columns:
    name: string(255)

BlogPostTag:
  columns:
    blog_post_id:
      type: integer
      primary: true
    tag_id:
      type: integer
      primary: true
  relations:
    BlogPost:
      local: blog_post_id
      foreign: id
      foreignAlias: BlogPostTags
    Tag:
      local: tag_id
      foreign: id
      foreignAlias: BlogPostTags

如果您不想/必须使用多对多关系,最好在多个列上使用唯一键。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Doctrine 1 和 Symfony 1 的多个主键? 的相关文章

随机推荐