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?
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
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();
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With