# :dependent =\> :destroy

**URL:** <https://www.ruby-forum.com/t/dependent-destroy/119625>\
**Category:** Rails\
**Created:** [November 8, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/dependent-destroy/119625 "2007-11-08T17:12:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 8, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/dependent-destroy/119625/1 "2007-11-08T17:12:48Z")

</div>

I have two tables: airlinememberships and loyaltycars. The loyaltycars  
table just keeps track of what car memberships people want to asscoiate  
with an airlinemembership program. So that means that loyaltycars  
belongs\_to =\> :airlinemmebership which means that I have a  
airlinemembership\_id column in my loyatlycars table. Then in my  
ailrinemebership table I have has\_many :loyaltycars, :dependent =\>  
:destroy.

So my question is when I delete an airlinemebership from the table does  
that also delete the asscoaition from the loyaltycars table based on the  
fact that I have a field in that table holding the airlinemembership id  
by way of that :destroy statement?

Also when looking at the documention for the models there is a :destroy  
and a :destroy\_all. What is the difference between the two. Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [November 8, 2007, 7:24pm UTC](https://www.ruby-forum.com/t/dependent-destroy/119625/2 "2007-11-08T19:24:21Z")

</div>

On Nov 8, 9:12 am, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> fact that I have a field in that table holding the airlinemembership id  
> by way of that :destroy statement?

Yes. But you must use destroy to delete the airlinemembership, not  
delete.

Be careful, delete just is lower level method to delete records as it  
skips any dependancy checking you may have. But it is faster if you  
need to delete a lot of records quickly and you don’t care about  
integrity checks.

> Also when looking at the documention for the models there is a :destroy  
> and a :destroy\_all. What is the difference between the two.

Destroy only worths with ids, and you can pass multiple id numbers to  
destroy. Destroy\_all can work with any condition you want, like  
airlinemembership.destroy( “active = false”).
