-1
this.store.findRecord('book',params.id).then(function(tag){
            tag.get('relatedBook').then(function(related){
                var items = related.get('related'); //items = '1,2,3'
                return related.store.query('book', {filter:{id: items} });
            });
        }),

Console still return localhost:8000/books?filter[id]=1,2,3, There still data in json api but When I call {{model}} in templates, it returns nothing?

What is the problem here?

Nam
  • 67
  • 1
  • 9

1 Answers1

-1

You are missing two return statements. Your model should look like this:

model() {
   return this.store.findRecord('book',params.id).then(function(tag){
        return tag.get('relatedBook').then(function(related){
            var items = related.get('related'); //items = '1,2,3'
            return related.store.query('book', {filter:{id: items} });
        });
    }),
}

The model hook expects you to return a promise, and then when you are chaining promises like this you must return the result of each of them, so the final result of your model hook will be the result of your last returned promise from the chain.

Community
  • 1
  • 1
Igor
  • 1,598
  • 11
  • 18
  • cool. Actually I do this with RSVP.hash() so I forgot 1 return at return tag.get('relatedBook'). anw Thank you so much – Nam Jun 17 '16 at 18:38