# Many to many and delete question

**URL:** <https://www.ruby-forum.com/t/many-to-many-and-delete-question/155630>\
**Category:** Rails\
**Created:** [December 15, 2008, 2:32am UTC](https://www.ruby-forum.com/t/many-to-many-and-delete-question/155630 "2008-12-15T02:32:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [December 15, 2008, 2:32am UTC](https://www.ruby-forum.com/t/many-to-many-and-delete-question/155630/1 "2008-12-15T02:32:07Z")

</div>

I have a “has\_and\_belongs\_to\_many” relationship between two tables,  
meaning I have a join table that contains the two ids of each table.

For simplicity let’s call them “foo” and “bar”. I want to delete a bar  
from a foo but not actually delete the bar itself.

foo = Foo.find(1)  
bar = Bar.find(1)

foo.bars \<\< bar  
foo.bars.delete(bar) # actually deletes the bar record which I don’t  
want

so what should I do to remove the association, but retain the bar  
record?

thanks

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [December 15, 2008, 5:54am UTC](https://www.ruby-forum.com/t/many-to-many-and-delete-question/155630/2 "2008-12-15T05:54:18Z")

</div>

But the above wont delete the bar record But delete only the  
association.
