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

Why no error message when trying to add a model to the same collection twice? #1142

Closed
alexgoldstone opened this issue Mar 26, 2012 · 1 comment
Labels

Comments

@alexgoldstone
Copy link

0.9.1 just threw a "Can't add the same model to a collection twice" error. This helped me identify and resolve a serious server-side bug that might have gone unnoticed for some time if the client-side error had not been thrown.

I see that duplicates are ignored silently as of 0.9.2 and this was clearly a conscious decision so I just wondered what the motivation for this was.

I can't think of a reason (other than a bug) for trying to add a duplicate model to a collection that can't support duplicates and I would therefore expect to see an error message even if the code is able to mitigate the error as 0.9.2 does.

@jashkenas
Copy link
Owner

For a long time -- our position and reasoning was along the same lines as yours: Duplicate models in a collection indicate an application logic error, and should be warned early.

But there are a number of folks who appreciate "sloppy" adds, where you can just keep trying to add models to a collection without checking if they're in there first -- so we made the change to be more forgiving.

Feel free to override your copy of Backbone.Collection.prototype.add with an early check and error if you like.

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

No branches or pull requests

2 participants