samedi 22 août 2015

Load two models in one JSON request in Ember-data 1.13.8

I have the following route:

this.resource('users', { path: '/'});

And the following two ember models: user and meta

When I go to the above route and array of users is loaded using the overriden model function:

model: function() {
        return this.store.findAll('user');
    },

the server returns the following JSON:

{
  "users" : [ {
    "id" : "ab650b0d-bea7-4619-a3fd-95f4c7bfd722",
    "firstName" : "Shivam",
    "lastName" : "Sinha",
    "username" : "shiv",
    "gender" : "M",
    "contactdetails" : [ {
      "id" : "fb5c9345-037e-4a57-9801-2b260b9b15fa",
      "name" : "Shiv",
      "type" : "PRIMARY_EMAIL",
      "value" : "ssdfsdfa@outlook.com",
      "userExist" : true,
      "isVerified" : false
    } ]
  } ],
  "meta" : {
    "sort" : "id: ASC",
    "size" : 20,
    "number" : 0,
    "totalPages" : 1,
    "numberOfElements" : 1,
    "totalElements" : 1,
    "firstPage" : true,
    "lastPage" : true
  }
}

The user model gets properly deserialized and is loaded as an ember model. However meta model is ignored. How can I also get the meta model to load properly as an ember model without actually having to do a separate request ?




Aucun commentaire:

Enregistrer un commentaire