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

Level: Beginner

Abhilash L R
ember-titbits
1 min readJun 1, 2018

--

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

--

--

Abhilash L R
ember-titbits

Loves to travel, writes about programming, photography, life lessons and sometimes cooking