ember.js - Ember Data: working with API that returns larger payload on details endpoint than list endpoint -


i'm using ember ember data , working rest api returns small set of properties @ list endpoint , full payload @ details endpoint. example:

url: /api/users

{     "users":[         {"id":1,"name":"bob"},         {"id":2,"name":"sam"}     ] } 

url: /api/users/1

{     "user":{         "id":1,         "name": "bob",         "description": "lorem ipsum dolor"     } } 

notice how /api/users/1 returns more properties list. ember data, how fetch full payload when necessary if have routes set follows?

app.usersroute = ember.route.extend({     model: function () {         return this.store.find('user');     } });  app.userroute = ember.route.extend({     model: function (params) {         return this.store.find('user', params.user_id);     } }); 

the problem line:

this.store.find('user', params.user_id) 

it doensn't request full payload server if list has loaded, calling store's find method returns user limited properties cache.

you like:

  var user = this.store.getbyid('user', params.user_id);   if (user) {     return user.reload();   } else {     return this.store.find('user', params.user_id);   } 

check store methods (getbyid, hasrecordforid, recordisloaded) , model reload.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -