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
Trigger a 'collision' event when there's an collision by ids. #295
This is to open a discussion whether there's really a bug here, and if so, how to fix it.
This collision can arise from the following sequence:
Should this be allowed to happen? Doesn't this violate some fundamental assumptions made by BBR? What should happen in this case? This patch takes the approach that only the model itself will know how to appropriately resolve the conflict.
Let me know if you'd like more detail.
Then you should catch the error? If this situation occurs, relations on one or both of these models WILL be broken, and there's no way to tell on which they'll break, or in what way. Therefore, an error would be the only way out here. We'll need to get out before the duplicate
referenced this pull request
Mar 23, 2013
@PaulUithol I don't understand why you prefer throwing an error in this case, rather than triggering an event. I don't see how I can catch this error without modifying backbone itself, since it's backbone itself that calls set() from within the success callback for the save() function (before any user-supplied hooks, too).
Here's the code from backbone:
And here's the stacktrace where it triggers this error:
If BBR triggered an event, I could handle the conflict, but how could I recover when it throws this error (assuming I don't want to patch backbone.js)?
I also am running into the issue in this case: Backbone is calling .set within the .fetch success callback. My assumption was that new versions with the same ID being added to a collection would replace or update the old version. Is there a way we can make sure this happens instead of just dying?