# Polymorphic destroy of resource

**URL:** <https://www.ruby-forum.com/t/polymorphic-destroy-of-resource/92789>\
**Category:** Rails\
**Created:** [April 24, 2007, 8:07am UTC](https://www.ruby-forum.com/t/polymorphic-destroy-of-resource/92789 "2007-04-24T08:07:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yottameter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@yottameter](https://www.ruby-forum.com/u/yottameter)\
**Post date:** [April 24, 2007, 8:07am UTC](https://www.ruby-forum.com/t/polymorphic-destroy-of-resource/92789/1 "2007-04-24T08:07:35Z")

</div>

I have a folder class which has a folder\_linkable, which links a  
folder id to items via their id and class. If the folder is destroyed,  
I want each linking destroyed, and then each item that is linked to  
destroyed. I have in the FolderLinking class:

belongs\_to :folder\_linkable, :polymorphic =\>  
true, :dependent=\> :destroy

but in my unit tests, the items that are connected with  
folder\_linkable are not destroyed. Does dependent destroy work with  
polymorphic=\>true?

Otherwise, should I overload destroy, destroying the item, and then  
deleting the item via the class delete to avoid the recursive destroy?

---

<div class="post-metadata">

**Author:** ![yottameter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/df705f/32.png) [@yottameter](https://www.ruby-forum.com/u/yottameter)\
**Post date:** [April 25, 2007, 9:11pm UTC](https://www.ruby-forum.com/t/polymorphic-destroy-of-resource/92789/2 "2007-04-25T21:11:16Z")

</div>

I ran into the same problem a few days ago and havn’t found a solution  
to  
this. I really wonder if this is a bug (or a missing feature) in rails  
or if  
I’m just missing something.

Regards,  
Timo
