1
votes

i am trying to set a has many array of a object i am creating

  var template = {
    title:this.get('model').get('title'),
  }
  template = this.store.createRecord('template', template);
  template.get('sections').pushObjects(this.get('model').get('sections').map(function(x){return x}));

this.get('model').get('sections') is the same object as template.sections

but i keep getting the following error: Assertion Failed: The content property of DS.PromiseArray should be set before modifying it

I don't want to save the object on the server before I set the sections

1

1 Answers

2
votes

Even if sections is empty it's still a promise (since it's async), so you'll still want to then(...) it before you attempt to use it.

var otherSections = this.get('model.sections').toArray();
template.get('sections').then(function(sections){
   sections.pushObjects(otherSections);
})