我有複雜的關係,包括2種型號。我想創建解決我的目的的自定義方法。我有MySQL數據庫作爲datasouce。與2種型號的複雜關係
3主要型號。
藝術家,專輯,歌曲。 N的關係通過模式「曲目」:
專輯和歌曲相關2彼此用N。藝術家和曲目通過完整的模型「曲目藝術家」連接。 我希望通過這種關係獲得特定藝術家的專輯和歌曲列表。雖然我用補丁實現,但它返回重複列表,同時我想要唯一的記錄列表。請幫忙。
我只是在這裏提到模型關係對象而不是完整的模型對象。
artist.json
{
"name": "Artist",
"relations": {
"tracklists": {
"type": "hasMany",
"model": "Tracklist",
"foreignKey": "",
"through": "TracklistArtist"
}
}
}
album.json
{
"name" : "Album",
"relations": {
"songs": {
"type": "hasMany",
"model": "Song",
"foreignKey": "",
"through": "Tracklist"
}
}
}
song.json
{
"name" : "Song",
"relations": {
"albums": {
"type": "hasMany",
"model": "Album",
"foreignKey": "",
"through": "Tracklist"
}
}
}
tracklist.json
{
"name": "Tracklist",
"relations": {
"album": {
"type": "belongsTo",
"model": "Album",
"foreignKey": ""
},
"song": {
"type": "belongsTo",
"model": "Song",
"foreignKey": ""
},
"artists": {
"type": "hasMany",
"model": "Artist",
"foreignKey": "",
"through": "TracklistArtist"
}
}
}
曲目列表-artist.json
{
"name": "TracklistArtist",
"relations": {
"artist": {
"type": "belongsTo",
"model": "Artist",
"foreignKey": ""
},
"tracklist": {
"type": "belongsTo",
"model": "Tracklist",
"foreignKey": ""
}
}
}
我已經檢查從環回的MySQL的連接器修補。這裏是鏈接。 Check Here
Artist.tracklists({
id: $stateParams.artistId,
filter: {
groupBY:"albumId",
include: {relation: "album", scope: {}},
}
}).$promise.then(function (data) {
});
能告訴你的實際代碼/查詢? http://stackoverflow.com/help/mcve – Cyrbil
你需要關係模型的json嗎? – Sankalp
這可能會有所幫助,加上您用來獲取相關藝術家專輯和歌曲列表的相關部分代碼 – Cyrbil