stackmob/stackmob-js-sdk — pull request #1 by DaanBroekhof (2012-06-25 14:49:13+00:00)
Title: Basic support for backbone-relational

backbone-relational (https://github.com/PaulUithol/Backbone-relational) is a nice backbone addon to use when using the StackMob API.

This pull request contains basic changes to make backbone-relational work with the StackMob:
* idAttribute naming
* relation changes after methods 'addRelationship', 'appendAndSave' and 'deleteAndSave' success

Things that work 'out of the box':
* model.get('name-of-relation') will return a collection (many) or an model instance (one)
* fetchExtended
* save() with non-new objects added or removed on relation collections (will pick id value, or array of id values for many relations)

Potential todos:
* 'fetchRelated' (from backbone-relational) could be optimized
* idAttribute naming could be automatically figured out
* make save() use 'addRelationship', 'appendAndSave' and 'deleteAndSave' when manipulating large updates

Example usage:
```javascript
StackMob.Category = StackMob.Model.extend({
schemaName: 'category',
idAttribute: 'category_id',
});

StackMob.Book = StackMob.Model.extend({
schemaName: 'book',
idAttribute: 'book_id',
relations: [
{
type: Backbone.HasOne,
key: 'owner',
relatedModel: StackMob.User,
includeInJSON: 'username',
},
{
type: Backbone.HasMany,
key: 'categories',
relatedModel: StackMob.Category,
includeInJSON: 'category_id',
}
],
});
```