node.js - Complicated relationship with 2 Thorough Models -


i have complicated relationship includes 2 thorough models. want create custom method solves purpose. have mysql db datasouce.

3 main models.

artist, album, songs.

album , song related 2 each other n:n relationship through model "tracklist". artist , tracklist connected through thorough model "tracklistartist". wish list of albums , songs of particular artist through relationship. though achieved patches returns duplicate list , same time want unique record list. please help.

i mentioning model relation object here instead of complete model-object.

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"     }   } } 

tracklist-artist.json

{   "name": "tracklistartist",   "relations": {     "artist": {       "type": "belongsto",       "model": "artist",       "foreignkey": ""     },     "tracklist": {       "type": "belongsto",       "model": "tracklist",       "foreignkey": ""     }   }  } 

i have checked patched mysql-connector of loopback. here link. check here

 artist.tracklists({                 id: $stateparams.artistid,                 filter: {                    groupby:"albumid",                    include: {relation: "album", scope: {}},                 }             }).$promise.then(function (data) {             }); 

you propably need chain include every relations like:

artist.find({   include: {     relation: 'tracklist',     scope: {       include: {         relation: ['album', 'song']       }     }   },   where: {id: 12345} }, function() { ... }); 

edit:

artist.find({   include: {     relation: 'tracklist',     scope: {       include: {         relation: ['album']       },       scope: {           include: {             relation: 'tracklist',             scope: {                 include: {                    relation: ['song']                 }             }         }     }   },   where: {id: 12345} }, function() { ... }); 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -