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

后端 未结 14 2260
灰色年华
灰色年华 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条回答
  •  猫巷女王i
    2020-11-22 11:43

    This really useful example. It lacks in the documentation doctrine 2.

    Very thank you.

    For the proxies functions can be done :

    class AlbumTrack extends AlbumTrackAbstract {
       ... proxy method.
       function getTitle() {} 
    }
    
    class TrackAlbum extends AlbumTrackAbstract {
       ... proxy method.
       function getTitle() {}
    }
    
    class AlbumTrackAbstract {
       private $id;
       ....
    }
    

    and

    /** @OneToMany(targetEntity="TrackAlbum", mappedBy="album") */
    protected $tracklist;
    
    /** @OneToMany(targetEntity="AlbumTrack", mappedBy="track") */
    protected $albumsFeaturingThisTrack;
    

提交回复
热议问题