Created
April 18, 2011 06:02
-
-
Save scottharvey/924881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MilestoneModel = Backbone.Model.extend({ | |
initialize: function(attrs) { | |
this.hasMany('Tasks', 'milestone_id'); | |
} | |
}); | |
TaskModel = Backbone.Model.extend({ | |
initialize: function(attrs) { | |
this.belongsTo('Milestones', 'milestone_id'); | |
} | |
}); | |
var milestone = new MilestoneModel({ id: 1 }); | |
var task = new TaskModel({ id: 2, milestone_id: 1}); | |
milestone.tasks(); // Returns a Backbone collection of Tasks with milestone_id == 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MilestoneCollection = Backbone.Collection.extend({
initialize: function() {
}
});
TaskModel = Backbone.Model.extend({
initialize: function() {
}
});
var milestone = new MilestoneCollection;
var task = new TaskModel({ id: 2, milestone_id: 1});
milestone.add(task);
milestone.models;