モデルに添付されたコレクションがあります。ボタンをクリックしたときに、その 1 つの属性 (コレクションを含む) のみをサーバーに保存するようにバックボーンに指示できるようにしたいと考えています。
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');
});
});
そして、サーバーに送信したい:
POST /api/surveys/123/
{
invites: [
{<invite1>}, {<invite2>}, {<invitex>}
]
}