1
votes

I am having a problem with a hasMany property, but only under certain circumstances. I have a User model and a Group model. The user has a property:

groups: hasMany('group', { async: true })

In my template, I show the groups:

{{#each groups}}<span class="label">{{this.name}}</span>{{/each}}

When I go to /users/1, I see the groups. Then I can go to /users/1/edit. There, I show a Ember.Select view with multiple=true. The select view shows 'groups' as the selection and 'allGroups' as the full list. This works as expected. 'allGroups' is a computed property on UserEditController:

allGroups: function() {
    return this.store.find('group');
}.property()

So far, so good. I can update the selected groups if I want, then save. After the save, I transition back to the /users/1 route. When the user is displayed there (after updating), the selected groups show nothing. No error in the console.

I can refresh the page and the selected groups are shown, showing the new choices I made when updating the user.

This one has me baffled, but I suspect it has something to do with the 'allGroups' function.

2

2 Answers

0
votes

What version of Ember-Data are you using? This sounds like known bug that should be fixed in 1.0.0-beta-3:

https://github.com/emberjs/data/commit/4d717bff53f8c93bedbe74e7965a4f439882e259 https://github.com/emberjs/data/issues/1228 http://discuss.emberjs.com/t/hasmany-relationships-and-waiting-for-all-child-models-to-be-loaded/2461/3

The second link contains a workaround that should work if you have to use an earlier version of ember-data.

0
votes

I ran into this issue before, but in this case you don't need to manually handle the synchronicity. Ember will render the data when it receives it...

Please provide more code and I will take a look, I think this could be related to the way you proceed for saving.

Also, although I am note sure about that, when you proceed to an update your backend, I think, should return the "inserted" or "updated" data. This would help to ensure synchronization with the backend.