0

I have has many relation of 2 models via third through model in Loopback. My models are :

  1. Song
  2. Album
  3. Tracklist (- Thorough Model having songId & albumId as field.)

How would I make request in Song model for relating album with it? What I have tried is -

$scope.tagAdded = function () { 
    Song.albums.link({id: $scope.songId, fk: $scope.albumId},
    {albumId: $scope.albumId, songId: $scope.songId})
        .$promise
        .then(function (value) {
            console.log(value);
        }, function (reason) {
        });
    }; 

Relations are proper. But its not adding data, at same time I wish if instance is already saved means relation is already made it won't save it. Don't create duplicate records.

Sankalp
  • 1,300
  • 5
  • 28
  • 52
  • Please, complete your question with model's json configuration (only properties and relations). I noticed, some error in your code, but I must be sure to answer. – IvanZh Mar 26 '15 at 16:41
  • Its complete. I have shown relationship above. Please ask if you have any doubt. – Sankalp Mar 27 '15 at 03:18
  • What is the name of your Through relation? What extra relations do you have between your models? – IvanZh Mar 27 '15 at 07:22

0 Answers0