Skip to content

Instantly share code, notes, and snippets.

@andrewdeandrade
Created February 25, 2011 21:55
Show Gist options
  • Save andrewdeandrade/844569 to your computer and use it in GitHub Desktop.
Save andrewdeandrade/844569 to your computer and use it in GitHub Desktop.
updating model with nested collection attribute
Project = Backbone.Model.extend({
initialize: function() {
_.bindAll(this, 'getRules', 'saveRules');
this.getRules();
this.rules.bind('add', this.saveRules);
this.rules.bind('remove', this.saveRules);
},
getRules: function() {
var rules = this.get("rules");
this.rules = new RulesCollection(rules);
},
saveRules: function() {
this.set({ "rules": this.rules });
},
save: function() {
this.collection.update(this);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment