I have a collection that's attached to a model. When I click a button, I would like to be able to tell backbone to save only that one attribute (containing the collection) to the server
m.Survey = m.BaseModel.extend({
relations: [{
type: Backbone.HasMany,
key: 'invites',
relatedModel: 'APP.Models.SurveyInvite',
collectionType: 'APP.Collections.SurveyInvites',
//save invites separately
includeInJSON: false,
reverseRelation: {
key: 'survey',
//We don't want to list the survey when doing toJSON()
includeInJSON: false
}
}],
//need this method
saveInvites: function(){
this.saveOnly('invites');
});
});
And I want it to send to the server:
POST /api/surveys/123/
{
invites: [
{<invite1>}, {<invite2>}, {<invitex>}
]
}