samedi 9 mai 2015

Ember Data: CreateRecord not updating model when using store.find with query params

When my route model uses this.store.find('user') it updates automatically and the template shows new records created using createRecord. So the following works as expected:

Route:

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

Template:

{{#each user in model}}
      {{user.username}}<br>
{{/each}}

Controller Code:

  // Triggered when form submitted to create a new user
  var newUser = this.store.createRecord('user', {
    username: this.get('username').trim()
  });
  // new user shows up in template immediately after createRecord

If I change my route model to use the query params version of find the template no longer updates when I do a createRecord

Route:

  model: function(){
    // query params version of store.find
    return this.store.find('user', {enabledOnly: false, limit: 100});
  }

Controller Code:

  // Triggered when form submitted to create a new user
  var newUser = this.store.createRecord('user', {
    username: this.get('username').trim()
  });
  // new user does not show up in template at all

It seems like this might be a bug as the only change in the code is switching from the basic find('user') to the version that has query params. Is this expected behavior for ember data? Why would the model not update the template after createRecord is called when the query param version of find is used (i.e., find('user', {}))

Thank you!




Aucun commentaire:

Enregistrer un commentaire