dhruvaray / backbone-associations

Create object hierarchies with Backbone models; Respond to hierarchy changes using regular Backbone events.
http://dhruvaray.github.io/backbone-associations/
MIT License
492 stars 75 forks source link

Setting same fires remove/add/sort #143

Open Muon opened 10 years ago

Muon commented 10 years ago

Setting the same contents fires events even if nothing has changed, see fiddle for example: http://jsfiddle.net/xNWUM/1/

Muon commented 10 years ago

Hmm, this seems to be tied to the id attribute. Two models seems only seem to be considered same if they have the same id.

dhruvaray commented 10 years ago

This is in line with Backbone behavior. We use Backbone's smart set method internally for 1:M relations.(all working on id)

From Backbone documentation

If you want to smartly update the contents of a Collection, adding new models, removing missing ones, and merging those already present, you now call set (previously named "update"), a similar operation to calling set on a Model. This is now the default when you call fetch on a collection. To get the old behavior, pass {reset: true}.

This internally calls add/remove/sort. Search for _addReference, _removeReference in http://backbonejs.org/docs/backbone.html

Muon commented 10 years ago

Hmm, that's awkward. So what should I do if my data is just... data? Just give them arbitrary different ids?