0

I have 2 Models that are related through hasAndBelongsToMany Releationship through 3 intermediate model. eg. Artist is related to Tracklist model through third intermediate model TracklistArtist. Tracklist model have belongsTo with Song model.

I want to fetch song related with the particular artist.

Artist.tracklists({
    id: $stateParams.artistId,
    filter: {                 
        include: [{relation:"song",scope:{limit:2}}]
    }
}).$promise.then(function (data) {
    $scope.items = data;
});

I am referring link to filter the include condition from this link. IncludeFilter

Issue is --

  1. its not limiting the relational data of song. I am applying pagination so I want limited data of song Model.
  2. I wish to find unique song. How to implement distinct to song model.
Sankalp
  • 1,300
  • 5
  • 28
  • 52
  • When you say "limited data," do you mean that you want a subset of all the properties for `Song` to show up? or something else? As an aside, usually for pagination two filters are used: `{skip:0,limit:5}` and I don't the use of `skip` filter in your sample code. – pulkitsinghal Aug 19 '15 at 13:29
  • I know two filters for pagination. I want to limit data of 'Song' Model fetched from quering Artist model through intermediate model. – Sankalp Aug 20 '15 at 07:33
  • Did @JSimonsen answer your question? As you can see he uses `{ }` where you use `[ ]` ... also if you want a quick way of troubleshooting syntax in loopbackjs then you can try `loopback-console` ... I can help you with a walkthrough in the stackoverflow chat room for loopbackjs: https://chat.stackoverflow.com/rooms/87665/loopbackjs ... and you may also try the Gitter chat room that has a lot of community members: https://gitter.im/strongloop/loopback – pulkitsinghal Aug 22 '15 at 22:16

1 Answers1

0

To use the limit feature you can want to write this like below as indicated by the documentation

include: {
    relation: 'song',
    scope: { 
      limit:5
    }
  }
JSimonsen
  • 2,642
  • 1
  • 13
  • 13