Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Backbone Relational+Mongoose, how do I RESTfully save a collection that's an attribute of a model?
    primarykey
    data
    text
    <p>In backbone, I have a model with the following structure:</p> <pre><code>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 } }] }); </code></pre> <p>On the server side I have the same schema</p> <pre><code>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], }); </code></pre> <p>In my application, I create the collection of invite models, and then need to send the list of invites to the server to be saved. Later I may send a new collection to update the invites (removing or adding).</p> <ol> <li>How do I tell Backbone to send just the invites attribute to the server (to say /api/survey/[id]/invites</li> <li>How do I tell the server to clear the invites array and replace it with the survey input</li> <li>What should server return to Backbone so that it properly updates in Backbone Relational (giving the correct IDs to my invites).</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload