Skip to content

Instantly share code, notes, and snippets.

@dunkfordyce
Created October 24, 2011 10:25
Show Gist options
  • Save dunkfordyce/1308738 to your computer and use it in GitHub Desktop.
Save dunkfordyce/1308738 to your computer and use it in GitHub Desktop.
/*commonjs*/
var Backbone = require('mobile/backbone_base'),
Deferred = require('mobile/deferred').Deferred,
Campaigns = require('mobile/model/campaigns').Campaigns,
url_for = require('mobile/url_for').url_for;
exports.Account = Backbone.Model.extend({
campaigns: function() {
if( !this._campaigns ) {
this._campaigns = new Campaigns([], {account_id: this.id});
}
return this._campaigns;
}
});
exports.Accounts = Backbone.Collection.extend({
model: exports.Account,
url: url_for('mobile_accounts'),
all: function() {
if( this._all_promise ) { return this._all_promise; }
var p = this._all_promise = Deferred(), self = this;
this.fetch({success: function() {
Ti.API.info('done all '+ self.models.length);
p.resolve(self);
}});
return this._all_promise;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment