Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasMany properties do not interact correctly with computed array properties #447

Open
mongoose700 opened this issue Oct 17, 2016 · 0 comments

Comments

@mongoose700
Copy link

mongoose700 commented Oct 17, 2016

When you have a hasMany property, and define another property using as follows:

people: hasMany(Thing, { key: 'thing_ids' }),
peopleNames: Ember.computed.mapBy('people', 'name'),

then peopleNames will not update correctly when people changes. I've traced the issue to computedPropertySet in ember.js, where it performs the set

ret = setter.call(obj, keyName, value, cachedValue);

In ember-model.js, this ends up being

return existingArray.setObjects(newContentArray)

where existingArray is cachedValue and newContentArray is value. That is, it mutates the cached value and returns it, instead of returning a new, independent value. Thus, when computedPropertySet gets to

if (hadCachedValue && cachedValue === ret) {
  return;
}

the comparison will be true, and it will return before getting to the logic to check if it is being watched and call propertyDidChange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant