javascript - How can i save nested models -
i'm working on ember.js project uses ember data , restadapter.
my model exists out of questions , possible answers.
app.question = ds.model.extend({     answers: ds.hasmany('app.answer'),     text: ds.attr('string'),     image: ds.attr('string') });  app.answer = ds.model.extend({     question: ds.belongsto('app.question'),     text: ds.attr('string'),     image: ds.attr('string') });   my view modal, in can create or edit questions , answers. questions , possible answers should saved on hitting save button, or on uploading image.
the problem saving procedure complicated.
- in order upload image of answer, need make sure answer exists on server.
 - in order save answer, need make sure question exists.
 
is way tell ember save whole question, it's answers, @ once?
i think solution might workaround problem:
ds.restadapter.map('app.question', { answers: {embedded: 'always'} });   see instance: ember.js commiting parent model existing child models
much more on relationships can found in breaking changes: https://github.com/emberjs/data/blob/master/breaking_changes.md
Comments
Post a Comment