documentcloud/backbone — Issue #666: collection.add(model_instance) does not set collection of model
Author: gr2m
Created: 2011-10-11 17:42:05+00:00
State: open

If this is a feature, would you mind to explain?

If this is a bug, I'd be happy to provide a patch and send a pull request. I'd adjust the code of `_prepareModel` to set collection in any case unless it's already set.

```javascript
_prepareModel: function(model, options) {
if (!(model instanceof Backbone.Model)) {
var attrs = model;
model = new this.model(attrs, {collection: this});
if (model.validate && !model._performValidation(attrs, options)) model = false;
} else if (!model.collection) {
model.collection = this;
}
return model;
},
```