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(
I believe we've to do something with (or around) Backbone sync
or with rails backend, because the problem in communication between two. Overriding toJSON()
method might lead to unexpected results, because this is general purpose method and others parts of application might rely on, for example views.
Possibly quick solution:
redCar.save({}, {
contentType: 'application/json',
data: JSON.stringify({car: redCar.toJSON(), engines_attributes: redCar.get('engines').toJSON()})
});