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],
});
在我的应用程序中,我创建了邀请模型集合,然后需要将邀请列表发送到要保存的服务器。稍后,我可能会发送一个新集合来更新邀请(删除或添加)

  • 如何告诉主干网只向服务器发送invites属性(比如/api/survey/[id]/invites)
  • 我如何告诉服务器清除邀请数组并用调查输入替换它
  • 服务器应该返回到主干网,以便在主干网关系中正确更新(为我的邀请提供正确的ID)