Doctrine2: Best way to handle many-to-many with extra columns in reference table

后端 未结 14 2257
灰色年华
灰色年华 2020-11-22 10:44

I\'m wondering what\'s the best, the cleanest and the most simply way to work with many-to-many relations in Doctrine2.

Let\'s assume that we\'ve got an album like

14条回答
  •  半阙折子戏
    2020-11-22 11:21

    Unidirectional. Just add the inversedBy:(Foreign Column Name) to make it Bidirectional.

    # config/yaml/ProductStore.dcm.yml
    ProductStore:
      type: entity
      id:
        product:
          associationKey: true
        store:
          associationKey: true
      fields:
        status:
          type: integer(1)
        createdAt:
          type: datetime
        updatedAt:
          type: datetime
      manyToOne:
        product:
          targetEntity: Product
          joinColumn:
            name: product_id
            referencedColumnName: id
        store:
          targetEntity: Store
          joinColumn:
            name: store_id
            referencedColumnName: id
    

    I hope it helps. See you.

提交回复
热议问题