Skip to content

Instantly share code, notes, and snippets.

@jasonm
Created August 28, 2011 18:16
Show Gist options
  • Save jasonm/1177000 to your computer and use it in GitHub Desktop.
Save jasonm/1177000 to your computer and use it in GitHub Desktop.
Backbone.Collection.prototype._addWithIdCheck = function(model, options) {
var idAttribute = model.idAttribute || this.model.prototype.idAttribute;
var modelId = model[idAttribute];
if (this.get(modelId) === undefined) {
this._addWithoutIdCheck(model, options);
}
};
Backbone.Collection.prototype._addWithoutIdCheck = Backbone.Collection.prototype._add;
Backbone.Collection.prototype._add = Backbone.Collection.prototype._addWithIdCheck;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment