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

后端 未结 14 2203
灰色年华
灰色年华 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:43

    Nothing beats a nice example

    For people looking for a clean coding example of an one-to-many/many-to-one associations between the 3 participating classes to store extra attributes in the relation check this site out:

    nice example of one-to-many/many-to-one associations between the 3 participating classes

    Think about your primary keys

    Also think about your primary key. You can often use composite keys for relationships like this. Doctrine natively supports this. You can make your referenced entities into ids. Check the documentation on composite keys here

提交回复
热议问题