在骨干网中,我有一个具有以下结构的模型:
m.Survey = m.BaseModel.extend({
initialize: function() {
this.saveInvites = _.debounce(this.saveInvites, 1000);
},
/**
* What should this function do?!
* @return {[type]}
*/
saveInvites: function(){
},
urlRoot: '/api/surveys',
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
}
}]
});
在服务器端,我有相同的架构
var SurveyInviteSchema = new Schema({
account: {type: Schema.Types.ObjectId, ref: 'Account', required: true},
survey: {type: Schema.Types.ObjectId, ref: 'Survey', required: true},
key: String
});
var SurveySchema = new Schema({
start_date: Date,
end_date: Date,
title: String,
invites: [SurveyInviteSchema],
});
在我的应用程序中,我创建了邀请模型的集合,然后需要将邀请列表发送到要保存的服务器。稍后我可能会发送一个新的集合来更新邀请(删除或添加)。