Backbone.js 使用主干关系+;Mongoose,如何RESTfully保存一个';模型的属性是什么?
在主干中,我有一个具有以下结构的模型:Backbone.js 使用主干关系+;Mongoose,如何RESTfully保存一个';模型的属性是什么?,backbone.js,mongoose,backbone-relational,Backbone.js,Mongoose,Backbone Relational,在主干中,我有一个具有以下结构的模型: m.Survey = m.BaseModel.extend({ initialize: function() { this.saveInvites = _.debounce(this.saveInvites, 1000); }, /** * What should this function do?! * @return {[type]}
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],
});
在我的应用程序中,我创建了邀请模型集合,然后需要将邀请列表发送到要保存的服务器。稍后,我可能会发送一个新集合来更新邀请(删除或添加)