Ember data load model using findQuery

03:58 Anil Maurya 2 Comments

Loading Ember model in route is as simple as:

App.PostsRoute = Ember.Route.extend({
  model: function(params) {
     return this.store.find('post', params.post_id);
  }
});

But when loading model using findQuery then

App.PostsRoute = Ember.Route.extend({
  modelfunction(params) {
     return this.store.find('person, {name: params.username}).then(function(result){

        return result.get('firstObject')

     });

  }
});


findQuery return Array therefore select firstObject from Array, Remember to return Array from api for '/persons?name=test_name' url.

2 comments :

  1. I love you, this has solved my problem !:D

    ReplyDelete
    Replies
    1. I'm glad to hear that it solved your problem. Happy Coding :)

      Delete