Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Collection#fetch updates existing model instances (vs replacing) #955
If I create a new model, and then call fetch, it will update that model's attributes.
If I create a collection of models, and then call fetch, it won't update the existing models – it will replace them with new instances.
This is painful because I cannot cache references to the collection's model instances, as the references become invalid once a fetch occurs. Instead I'd have to cache references to the collection, and do Collection#get every time I want to access the model. Maybe that's acceptable, but it seems reasonable that a collection should be able to perform a fetch/update without invalidating existing model instances.
How would you want to handle "add" events to the collection if you're only updating a model? Would you want your change event to fire instead? I can see situations where both would be valid behaviors (throw-away views vs carefully managed views etc.)
We've used custom extension to do exactly that in Wunderkit as well -
edit: hm I'm wondering if we could implement kind of "sync" behavior here - for example a fetch returns same collection - but some models are gone, some are changed and some are added. Now it should not only check vs models if they already exist but it should also check if any models weren't removed so they should get removed from the collection as well. Something to think about :)
pushed a commit
Feb 10, 2012
referenced this issue
Mar 5, 2012
I'd be glad to entertain a pull request for "smart" resets, but -- they're already easy to accomplish with the tools backbone gives you:
Furthermore, you'd have to deal with a number of API choices, most of which have no "right" answer: