I have a Backbone Model that contains a collection:
var Stream = Backbone.Model.extend({
defaults: {
dummyField: "1",
excludedUsers: new Backbone.Collection()
}
});
var s = new Stream;
s.get('excludedUsers').add( {name:'Stefan'} );
console.log(s.toJSON())
yields:
{ dummyField: '1',
excludedUsers:
{ length: 1,
models: [ [Object] ],
_byId: {},
_byCid: { c1: [Object] } } }
instead of the "expected":
{
dummyField: '1',
excludedUsers: [ {name:'Stefan'} ]
}
because Backbone isn't deeply JSONing the Model. The only way of working around is to override the toJSON method on the Stream's prototype but that won't help for other cases. Is there a general/better solution (besides the heavy Backbone.Relational plugin) already?