tgriesser/bookshelf — pull request #276 by jordwest (2014-03-09 01:03:51+00:00)
Title: Suggested improvement for client-side generated IDs (eg UUIDs)

This change simplifies situations where the ID is generated by the client rather than by the database.

Current solutions hook into the 'saving' event to generate an ID, which means that the generated ID cannot be retrieved by the client before the model is saved. This removes one of the advantages of using UUIDs - if you know the ID before saving you can fire off multiple save queries for related models in parallel.

This pull request allows the ID generation function to be specified on the model definition - for example:
```javascript
var Uuid = Bookshelf.Model.extend({
idAttribute: 'uuid',
tableName: 'uuid_test',
generateId: function(){
return uuid.v4();
},
});
```

**This change overrides the backbone.js isNew function**. This doesn't break any existing tests - except a single test: "uses the idAttribute to determine if the model isNew". This test was replaced with three others which better capture the expected behaviour of isNew.