# How to handle orphans?

**URL:** <https://www.ruby-forum.com/t/how-to-handle-orphans/206731>\
**Category:** Rails\
**Created:** [May 8, 2011, 8:25pm UTC](https://www.ruby-forum.com/t/how-to-handle-orphans/206731 "2011-05-08T20:25:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [May 8, 2011, 8:25pm UTC](https://www.ruby-forum.com/t/how-to-handle-orphans/206731/1 "2011-05-08T20:25:16Z")

</div>

The requirements for my Web app have changed and now instead of  
destroying an  
object and all children when it expires, I need to destroy the parent  
object  
when the last child is destroyed. Is there a builtin or gem to do this?  
Is  
it better to check the cached count in the parent (reference counting)  
and  
destroy it when drops to zero when each child is destroyed or  
periodically  
scan for parents with no children and destroy them then (garbage  
collection)?

TIA,  
Jeffrey
