# Polymorphic destroy of resource

**URL:** <https://www.ruby-forum.com/t/polymorphic-destroy-of-resource/92856>\
**Category:** Rails\
**Created:** [April 25, 2007, 2:54am UTC](https://www.ruby-forum.com/t/polymorphic-destroy-of-resource/92856 "2007-04-25T02:54:22Z")\
**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 25, 2007, 2:54am UTC](https://www.ruby-forum.com/t/polymorphic-destroy-of-resource/92856/1 "2007-04-25T02:54:22Z")

</div>

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?

This doesn’t work:

class FolderLinking \< ActiveRecord::Base

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

when an instance of FolderLinking is destroyed, I want the item that  
it links to destroyed. I’m currently seeing the folder\_linkable  
sticking around.

---

<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 27, 2007, 10:26pm UTC](https://www.ruby-forum.com/t/polymorphic-destroy-of-resource/92856/2 "2007-04-27T22:26:19Z")

</div>

Yottameter \<yottameter@…\> writes:

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

Specifying :dependent=\> :destroy on the has\_one declaration causes the  
“parent”  
to be destroyed with the resource. You must, however, destroy the  
resource, not  
the parent, which seems a bit upside-down.

-wcpr-
