Company
Date Published
Author
Nathan Kontny
Word count
952
Language
English
Hacker News points
None

Summary

Daddy Warbucks: You lock the orphans in the closet. Miss Hannigan: They love it! If you're using a development framework to interact with data, you've likely had to make smart choices on how cascading deletes work in your system. You can have your app and framework manage all those deletes, keeping close control over validation and object lifecycles, or have your database handle the cascading deletes, but then lose things like lifecycle hooks. To address this, Rails is releasing a new utility called Miss Hannigan that provides an alternative way to do cascading deletes/destroys. This utility allows you to use a "nullify then later purge" approach, which has some of the best of both :destroy and :delete_all worlds. You can now add a :nullify_then_purge dependency to your has_many relationships, using this new utility. Additionally, Miss Hannigan uses batch destroys of the children, lowering the memory size of destroying a lot of children, and allows for post-destroy cleanup, while also handling foreign key constraints.