# How to delete from a HABTM table?

**URL:** <https://www.ruby-forum.com/t/how-to-delete-from-a-habtm-table/105578>\
**Category:** Rails\
**Created:** [May 31, 2007, 11:01am UTC](https://www.ruby-forum.com/t/how-to-delete-from-a-habtm-table/105578 "2007-05-31T11:01:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [May 31, 2007, 11:01am UTC](https://www.ruby-forum.com/t/how-to-delete-from-a-habtm-table/105578/1 "2007-05-31T11:01:16Z")

</div>

Thanks to the wonderful advice of everybody here, I finally understand  
how to add records to a HABTM table. You treat it like an array, and  
just use the “\<\<” concatenator to stick the new record on at the end.

But how do you delete a record?

i’ve tried to use arr.delete or arr.clear, like in the pickaxe book, but  
it’s not working. Can anyone give a quick rundown on the basics of  
deleting these kinds of associations?

Thanks!  
sean

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [June 2, 2007, 7:43pm UTC](https://www.ruby-forum.com/t/how-to-delete-from-a-habtm-table/105578/2 "2007-06-02T19:43:49Z")

</div>

Say Actor HABTM Movies.

If Actor with id == 25 is associated with a Movie with id == 213:

a = Actor.find(25)  
m = Movie.find(213)

then

```
 a.movies.delete(m)

```

will remove the association. It won’t delete the movie, just unlink  
them.

Can short-circuit with

a.movies.delete(Movie.find(213))

Sean C. wrote:

> Thanks to the wonderful advice of everybody here, I finally understand  
> how to add records to a HABTM table. You treat it like an array, and  
> just use the “\<\<” concatenator to stick the new record on at the end.
> 
> But how do you delete a record?
> 
> i’ve tried to use arr.delete or arr.clear, like in the pickaxe book, but  
> it’s not working. Can anyone give a quick rundown on the basics of  
> deleting these kinds of associations?
> 
> Thanks!  
> sean
