{{Quest 1}}: Orphaned ember data model cleanup

Level: Beginner

Abhilash L R
Jun 1, 2018 · 1 min read

Supposing that you have an index route which displays a list of all records of book and another route that creates a record for the same, then the newly created record will also be displayed as an empty item. For example: https://ember-twiddle.com/5b3175b92732d04e6132040271d0b911?openFiles=templates.application.hbs%2C

EmberJS Cookbook is a valid book while there is an orphaned empty record displayed during listing!

Since you are creating a new model it remains as an orphan and you need to manually destroy it (roll it back). This can be done in the route’s resetController hook. Something like below:

Refer: https://emberjs.com/api/ember-data/3.1/classes/DS.Model/methods/rollbackAttributes?anchor=rollbackAttributes

Version: 1.12+

PS: Clap if you liked, and don’t forget to follow me here: Abhilash or on Twitter @abhilashlr

Easy code samples to improve your Ember Engineering…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store