Computed properties on `hasMany` relationships don't update after model saves
See original GitHub issueWith Ember 3.0.0 (and also with 3.1.0-beta.1 and canary), but not with Ember <= 2.18.2, filterBy
on a hasMany
relationship aren’t being recomputed when a property changes on one of the underlying models.
Reproduced in a simple new app: https://github.com/pgengler/ember-update-bug.
The app consists of two <ul>
s, one displaying “saved” models (isNew=false
) and the other displaying “pending” models (isNew=true
), and a button that creates a new model and saves it. While it’s saving, it should appear in the “Pending” section and once the POST
completes (and isNew
gets sets to false on the model) it should then appear in the “Saved” section.
With Ember >= 3.0.0, a newly-created thing never moves from “Pending” (with <= 2.18.2 it works as expected). If I do some logging like this:
let task = this.get('store').createRecord('task', {
description: 'new task',
list: this.get('list')
});
next(function() {
task.save()
.then(() => console.log('task.isNew: %s', task.get('isNew'))
.then(() => console.log('tasks.mapBy(isNew): %O', list.get('tasks').mapBy('isNew'));
});
I see that isNew
for the new task has changed to false
(as expected) but the mapBy
returns [true]
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
It’s the same issue as https://github.com/emberjs/data/pull/5359
The workaround there is to set up the relationship after calling
createRecord
Just wanted to comment I’m still seeing this behavior in Ember 3.2.1 / Ember Data 3.1.1.