I\'m using Rails, backbone.js (learning this now). Let\'s say you have two models, Car and Engine.
var Car = Backbone.Model.extend({
initialize: function(
Very helpful. I was working with a similar situation, and this example did not work for me at first. In my example I have a has_many / belongs_to relation. For example a car has_many :tires.
The problem I encountered was that the tires_attributes needed to be nested INSIDE of the car json, not adjacent to it. I ended up with something like this:
toJSON: function(){
json = {car : this.attributes};
json.car.tires_attributes = this.get('tires').toJSON();
return json;
}
Hope this helps.