Ember store.push with hasMany not updating template?

Assuming the following models :

App.User = DS.Model.extend(
  email: DS.attr('string')
  session_users: DS.hasMany('sessionUser')
)

App.SessionUser = DS.Model.extend(
  user: DS.belongsTo('user')
  state: DS.attr('string')
  session: DS.belongsTo('session')
)

App.Session = DS.Model.extend(
  title: DS.attr('string')
  session_users: DS.hasMany('sessionUser')
)

      

Session_route.js.coffee route :

App.SessionRoute = Ember.Route.extend(
  model: (params) ->
    this.store.find('session', params.id)
)

      

And the following session.hbs template :

{{#each session_users}}
    {{state}}
{{/each}}

      

I am connected to a WebSocket thread, when a new SessionUser is created, I get a notification.
Here's session_controller.js.coffee to check for some payload being clicked:

payload =
    id: 20
    user: controller.store.getById('user', 2)
    session: controller.store.getById('session', 2)
    state: 'confirmed'
  controller.store.push('sessionUser', payload)

      

Using Ember Inspector (Chrome Extension) I can see that the session user was clicked and exists in the store with the correct relationship, but the template has not been updated.
When using store.createRecord, the template is actually updated, but I want to use push / pushPayload to use the existing serializers.

+2


source to share


1 answer


I'm pretty sure this is a known bug. We do something similar with a websocket: after we push the payload to create a addObject

post , we manually call to add it to the hasMany relation, for example.



var comment = store.push('comment', payload);
post.get('comments').addObject(comment);

      

+5


source







All Articles