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

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

    While getting all album tracks form inside album class, you'll generate one more query for one more record. That's because of proxy method. There's another example of my code (see last post in topic): http://groups.google.com/group/doctrine-user/browse_thread/thread/d1d87c96052e76f7/436b896e83c10868#436b896e83c10868

    Is there any other method to resolve that? Isn't a single join a better solution?

    0 讨论(0)
  • 2020-11-22 11:46

    I've opened a similar question in the Doctrine user mailing list and got a really simple answer;

    consider the many to many relation as an entity itself, and then you realize you have 3 objects, linked between them with a one-to-many and many-to-one relation.

    http://groups.google.com/group/doctrine-user/browse_thread/thread/d1d87c96052e76f7/436b896e83c10868#436b896e83c10868

    Once a relation has data, it's no more a relation !

    0 讨论(0)
提交回复
热议问题