Ember.js - how to fetch additional record details? -
struggling populating ember data.
i'm using rails backend, , when hit /contacts.json (contactsroute), returns list of id, first, last -- works expected.
however, when visiting detail view (contactroute), hit /contacts/1.json , fetch details email address, anniversaries, etc. since have dynamic segment model hook skipped , none of associations available.
question: best approach fetching additional data in list/detail scenario?
models:
app.contact = ds.model.extend({   firstname: ds.attr('string'),   lastname: ds.attr('string'),   company: ds.attr('string'),   emails: ds.hasmany('app.email'), });  app.email = ds.model.extend({   contact: ds.belongsto('app.contact'),   emailaddress: ds.attr('string'), });   route:
app.router.map(function() {   this.resource('contacts');   this.resource('contact', {path: 'contacts/:contact_id'}); });  app.contactsroute = ember.route.extend({   init: function() {},   model: function() {     return app.contact.find();   } });  app.contactroute = ember.route.extend({   model: function(params) {     return app.contact.find(params.contact_id);   } });   thanks in advance.
i posted answer similar problem here: https://stackoverflow.com/a/18553153/1254484
basically, in app.contactroute, override setupcontroller method:
setupcontroller: function(controller, model) {   controller.set("model", model);   model.reload();   return; }   i'm using latest ember-data (commit ef11bff 2013-08-26).
Comments
Post a Comment