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

Optionally merging updated model state on collection add. #1220

Merged
merged 1 commit into from Apr 23, 2012

Conversation

Projects
None yet
4 participants
@folded
Contributor

folded commented Apr 13, 2012

The current behaviour of Backbone.Collection.add is to discard models that have matching ids. This makes it difficult to fetch and insert a set of models that may contain both new and updated models. Maybe there's a different way to perform this task, but it wasn't obvious to me.

This patch adds a merge flag to Backbone.Collection.add, which causes models with identical ids be passed as arguments to Backbone.Model.set instead of being discarded. In the case of true duplicates, the current behaviour is preserved (no change to the collection, no additional events fired), but updates to models retain the object in the collection, but update its attributes (firing the corresponding change events, unless silent).

jashkenas added a commit that referenced this pull request Apr 23, 2012

Merge pull request #1220 from folded/master
Optionally merging updated model state on collection add.

@jashkenas jashkenas merged commit 9ee0358 into jashkenas:master Apr 23, 2012

@jashkenas

This comment has been minimized.

Show comment
Hide comment
@jashkenas

jashkenas Apr 23, 2012

Owner

Thanks -- lovely implementation.

Owner

jashkenas commented Apr 23, 2012

Thanks -- lovely implementation.

@halfbaked

This comment has been minimized.

Show comment
Hide comment
@halfbaked

halfbaked Apr 26, 2012

Nice. Just what I was looking for.

halfbaked commented Apr 26, 2012

Nice. Just what I was looking for.

@nilbus

This comment has been minimized.

Show comment
Hide comment
@nilbus

nilbus Jul 28, 2012

Thank you! :-) Just what I needed as well.

nilbus commented on 7dbab65 Jul 28, 2012

Thank you! :-) Just what I needed as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment