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
You may be able to achieve what you want with Class Table Inheritance where you change AlbumTrackReference to AlbumTrack:
class AlbumTrack extends Track { /* ... */ }
And getTrackList()
would contain AlbumTrack
objects which you could then use like you want:
foreach($album->getTrackList() as $albumTrack)
{
echo sprintf("\t#%d - %-20s (%s) %s\n",
$albumTrack->getPosition(),
$albumTrack->getTitle(),
$albumTrack->getDuration()->format('H:i:s'),
$albumTrack->isPromoted() ? ' - PROMOTED!' : ''
);
}
You will need to examine this throughly to ensure you don't suffer performance-wise.
Your current set-up is simple, efficient, and easy to understand even if some of the semantics don't quite sit right with you.