mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Merge pull request #1295 from braddunbar/refactor-preparemodel
Refactor _prepareModel.
This commit is contained in:
17
backbone.js
17
backbone.js
@@ -820,16 +820,15 @@
|
||||
},
|
||||
|
||||
// Prepare a model or hash of attributes to be added to this collection.
|
||||
_prepareModel: function(model, options) {
|
||||
options || (options = {});
|
||||
if (!(model instanceof Model)) {
|
||||
var attrs = model;
|
||||
options.collection = this;
|
||||
model = new this.model(attrs, options);
|
||||
if (!model._validate(model.attributes, options)) model = false;
|
||||
} else if (!model.collection) {
|
||||
model.collection = this;
|
||||
_prepareModel: function(attrs, options) {
|
||||
if (attrs instanceof Model) {
|
||||
if (!attrs.collection) attrs.collection = this;
|
||||
return attrs;
|
||||
}
|
||||
options || (options = {});
|
||||
options.collection = this;
|
||||
var model = new this.model(attrs, options);
|
||||
if (!model._validate(model.attributes, options)) return false;
|
||||
return model;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user