Ember data concerns


I am using a mongo db based rest interface to provide json data to my ember application. My use case is pretty simple. I have Restaurants and Tables in my model, where Restaurant is related to Tables via hasMany relation.

  • When I query for the restaurant, I send the tables along side in the same object. Then ember complains that the object has to be loaded beforehand. So I have to load all the tables beforehand in the beforeModel callback.
  • If the tables under the restaurant do not have the type field (which my db doesn’t have), then ember throws an exception

Error while loading route: TypeError: Cannot set property ‘store’ of undefined at DS.Store.Ember.Object.extend.modelFor (http://localhost:5000/static/js/ember-data.js:2986:19) at DS.Store.Ember.Object.extend.recordForId (http://localhost:5000/static/js/ember-data.js:2437:17)

So I started providing a type field along with the embedded data and it works. However I still need to first fetch the tables before the restaurant.

  • Since the model returns _id I have

LiveKitchen.ApplicationSerializer = DS.RESTSerializer.extend({ normalize : function(type, hash, property) { console.log(‘Entered normaliser’); var json = hash; json.id = hash._id; delete json._id; return this._super(type, json, property); } });

This works normally, however when the restaurant is fetched and the tables are inside, ember is not calling this normaliser for those objects. Only the restaurant gets called. Hence the table elements do not match the ones I have preloaded in the beforeModel callback. Got this fixed again by sending the id from the server side.

Though I am able to get the data how I want now, the problem is I need to create an extra id field for every record and send it back.

I am pretty new to ember (2 weeks) and hence I could have made some mistake somewhere.