Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unload all records of a specific type from the store

I am trying to do the following:

App.Availablephone.all().forEach(function(phone, index) {
    phone.unloadRecord();
});

Unfortunately, since .all() is a live array, this is not working (the array is being modified during the loop, and gets completely mixed up).

How can I unload all records of a specific type from the store?

like image 578
blueFast Avatar asked Dec 29 '25 17:12

blueFast


2 Answers

While the selected answer works, ember-data provides an unloadAll method on the store that accomplishes this exact thing.

store.unloadAll('availablephone');

This works with the 1.0.0 beta releases, link to the source is below https://github.com/emberjs/data/blob/e4e3e3ec6b0289438a6b15c36407369fedf3eb40/packages/ember-data/lib/system/store.js#L717

like image 177
mspisars Avatar answered Jan 01 '26 11:01

mspisars


You can use the toArray method to get a static array of existing records.

var array = App.Availablephone.all().toArray();

// Records to unload:
array.forEach(function(item) { 
  console.log('unloading record: ', item.toString()); 
  item.unloadRecord();
})
like image 30
Mike Grassotti Avatar answered Jan 01 '26 12:01

Mike Grassotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!