doujiyan0971 2011-08-15 20:43
浏览 39

使用Doctrine 1和Symfony 1的多个主键?

I already know that's not possible to work with multiple primary keys in Symfony 1 and Doctrine 1, but do you guys know any good workarounds?

  • 写回答

2条回答 默认 最新

  • douruoshen1449 2011-08-15 21:08
    关注

    Beside many-to-many relationships doctrine1 does not work good with a primary key over multiple colums. But if you want to use many-to-many relationships use it like this:

    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
    

    If you DONT want/have to use many-to-many relationship its better to use a unique key over multiple columns.

    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退