jeudi 1 octobre 2015

Ember-Data reload model with parameters

Is it possible to reload a model with a parameter? I have overridden urlForFindRecord with this code:

urlForFindRecord(id, modelName, snapshot) {
  let url = this._super(...arguments);
  let query = Ember.get(snapshot, 'adapterOptions.query');
  if (query) {
    url += '?' + Ember.$.param(query);
  }
  return url;
}

This works perfectly when I call findRecord like so:

store.findRecord('type', 123, { adapterOptions: { query: { foo: 'bar' } } });

However, based on a property in another model, I need to reload my model. I can't just call model.reload() because I need the query param as part of my URL.

I also tried the following in my afterModel hook (because the query param is based on the other model):

store.findRecord('type', 123, { reload: true, adapterOptions: { query: { foo: 'bar' } } });

But the reload: true option doesn't work. There's a bug in ember-data preventing the reload from working. I tried hacking ember-data to allow it to reload, but despite it calling scheduleFetch it won't reload the model from the server.




Aucun commentaire:

Enregistrer un commentaire