documentcloud/backbone — pull request #1557 by iros (2012-08-16 21:14:55+00:00)
Title: Initializing collection from raw data doesn't pass it through parse method

JSFiddle Demonstrating issue:

http://jsfiddle.net/E26Pw/1/

Since parse is called when we perform a remote fetch, I see no reason why it shouldn't be called when initializing from an array of data if `parse` flag is set to true.

Currently in model constructor we call:

```javascript
if (options && options.parse) attributes = this.parse(attributes);
```

I propose changing the Collection constructor from:

```javascript
var Collection = Backbone.Collection = function(models, options) {
options || (options = {});
if (options.model) this.model = options.model;
if (options.comparator) this.comparator = options.comparator;
this._reset();
this.initialize.apply(this, arguments);
if (models) this.reset(models, {silent: true, parse: options.parse});
};
```

To:

```javascript
var Collection = Backbone.Collection = function(models, options) {
options || (options = {});
if (options.model) this.model = options.model;
if (options.comparator !== void 0) this.comparator = options.comparator;
this._reset();
this.initialize.apply(this, arguments);
if (models) {
if (options && options.parse) models = this.parse(models);
this.reset(models, {silent: true, parse: options.parse});
}
};
```

I realize that the parse flag is passed down to the models, meaning that either both get parsed or both don't, but I would argue that is expected behavior. If you have to parse the high level collection, then you should parse the models too.

I've added a test as well and all tests appear to pass without any issues.