balanced/balanced-dashboard — pull request #212 by kleinsch (2013-06-04 02:39:41+00:00)
Title: Model Promises

**Ready to merge**

Adds promises to models similar to how Ember Data uses them currently. Also fixes a nasty bug where belongsTo would sometimes return null. Enables you to do exciting things like this:

```javascript
Balanced.Marketplace.find('/v1/marketplaces/TEST-MP5m04ORxNlNDm1bB7nkcgSY').then(function(marketplace) {
return marketplace.get('owner_customer');
}).then(function(owner_customer) {
return owner_customer.get('bank_accounts');
}).then(function(bank_accounts) {
bank_accounts.forEach(function(bank_account) {
console.log(bank_account.get('uri'));
})
});
```

and this

```javascript
Balanced.Marketplace.find('/v1/marketplaces/TEST-MP5m04ORxNlNDm1bB7nkcgSY').then(function(marketplace) {
marketplace.set('name', "New Marketplace Name");
return marketplace.update();
}).then(function(marketplace) {
console.log("MARKETPLACE " + marketplace.get('name') + " WAS UPDATED");
})
```