mardi 1 décembre 2015

Save hasMany relation

I have Book model, which hasMany Chapter. User can add more chapters, then save the Book at once.

save(book) {

  book.get('actions').then(function(chapters) {
    chapters.forEach(function(chapter){
      if (chapter !== 'undefined') {
        if (chapter.get('isValid') === false) {
          chapter.deleteRecord();
        } else {
          action.save().then(function(savedChapter){
            book.get('chapters').pushObject(savedChapter);
          });
        }
      }
    });

  }).then(function(){
    // book.save();
  });

},

I can see the chapters in the database, but without bookId (null). If I try to save book at the end, it sends in the payload's reltationships:

{"chapters": data:[{type: "chapters", id: null}, {type: "chapters", id: null}]}




Aucun commentaire:

Enregistrer un commentaire