In ember data, calling destroyRecord in a forEach loop distorts the loop?

I am working on a simple tag model for one of my projects. I implemented something similar in Angular, but I wanted to try it out in Ember. Model Code Below

Tag = DS.Model.extend {
  name:DS.attr('string')
  user:DS.belongsTo('user')
  appliedTags:DS.hasMany('AppliedTag')

  obliterate:()->
    #destory the associated applied tags
    this.get('appliedTags').forEach( (appliedTag)->
      console.log(Ember.inspect(appliedTag))
      appliedTag.destoryRecord()
    )
    #destory the record
    this.destroyRecord()
}

fixtures = [
    id:1
    name:'Category 1'
    user:1
    appliedTags:[1,5]
]

Tag.reopenClass
  FIXTURES: fixtures

Everything is fine if I comment appliedTag.destoryRecord(). However, for the second time through the loop, it forEach appliedTaghas the value undefined .

+4
source share
1 answer

. , , , , . Ember hasMany , /. - , .

this.get('appliedTags').toArray().forEach( (appliedTag)->
  console.log(Ember.inspect(appliedTag))
  appliedTag.destoryRecord()
)
+6

All Articles