ManyToMany relationship with extra fields in symfony2 orm doctrine

前端 未结 2 1637
[愿得一人]
[愿得一人] 2021-01-28 02:52

Hi i have that same question as here: Many-to-many self relation with extra fields? but i cant find an answer :/ I tried first ManyToOne and at the other site OneToMany ... but

2条回答
  •  不思量自难忘°
    2021-01-28 03:20

    I was trying to have a many to many relationship with extra fields, and couldn't make it work either... The thing I read in a forum (can't remember where) was:

    If you add data to a relationship, then it's not a relationship anymore. It's a new entity.

    And it's the right thing to do. Create a new entity with the new fields, and if you need it, create a custom repository to add the methods you need.

    A <--- Many to many with field ---> B

    would become

    A --One to many--> C (with new fields) <-- One to many--B

    and of course, C has ManyToOne relationships with both A and B.

    I searched everywhere on how to do this, but in the end, it's the right thing to do, if you add data, it's no longer a relationship.

    You can also copy what contains usually do, or try to overwrite it in a custom repository, to do whatever you need it to do.

    I hope this helps.

提交回复
热议问题