documentcloud/backbone — pull request #773 by judofyr (2011-12-04 17:39:52+00:00)
Title: Collection.reset/add should invoke Model's parse function (with tests)

This fixes #588 and #616.

The use case is simple: You somehow ended up with a object structure from a remote server that *doesn't* fit the attributes in your model. With this patch you can pass `{parse:true}` to the model's constructor to invoke the parse function:

```javascript
Person = Backbone.Model.extend({
parse: function(obj) {
return { name: obj.fullName };
}
});

var fromServer = { fullName: 'Magnus Holm' };
var me = new Person(fromServer, {parse: true});
```

However, the *real* value of this, is that Collection.add/reset also supports it:

```javascript
col.add({fullName: 'Magnus Holm'}, {parse: true});
```

And finally, Collection.fetch *defaults* to it:

```javascript
col.fetch(); // is the same as col.fetch({parse: true})
```

This means that Collection.parse is only concerned with "convert this thingie to an array of other things", while Model.parse can worry about "convert a thing to its proper way".