Skip to content

Instantly share code, notes, and snippets.

@stevekane
Last active December 12, 2015 09:28
Show Gist options
  • Save stevekane/4751435 to your computer and use it in GitHub Desktop.
Save stevekane/4751435 to your computer and use it in GitHub Desktop.
How do I correctly delete records from Ember Data
Here is the problem:
I have a UI button that adds new instaces of a DS.Model (App.FarmAnimal....trolling here). I am implementing a route-wide "undo/redo" system and I need to construct all actions such that an "opposite" action is also available. I do not want to change a flag such as "isActive" on the model instance from true to false but rather I want to truly delete it. If the model has been persisted, I will take care of alerting the user that their undo will delete a persisted model... This is not a concern.
I have used the following pattern to add a new model to the related Objects array of my parent model (App.Farm).
App.Farm.get('farmanimal').createRecord({type:"pig"})
This works as intended but the reverse operation of deleting that record...not so much.
What is the correct pattern to target a record in the store and delete it? Assume that I do have access to the specific record object.
Thanks!
Steve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment