# Deleting HABTM

**URL:** <https://www.ruby-forum.com/t/deleting-habtm/125522>\
**Category:** Rails\
**Created:** [January 9, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/deleting-habtm/125522 "2008-01-09T22:27:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiddenhippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@hiddenhippo](https://www.ruby-forum.com/u/hiddenhippo)\
**Post date:** [January 9, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/deleting-habtm/125522/1 "2008-01-09T22:27:43Z")

</div>

Hi,

I’ve got a design which allows two objects in a HABTM, for example, an  
artist and cd’s; in that the artist can appear on many cds and many  
cds have the artist. to make the association i’ve been using

@cd.artist \<\< @artist

but i don’t know how to do the opposite. how do i remove the artist  
from a cd? if I attempt to simply do

@cd.artist.find(3).destroy it complains about not being able to find  
an artist\_id.

can anyone help?

thanks

---

<div class="post-metadata">

**Author:** ![hiddenhippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@hiddenhippo](https://www.ruby-forum.com/u/hiddenhippo)\
**Post date:** [January 9, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/deleting-habtm/125522/2 "2008-01-09T22:37:05Z")

</div>

I think i’ve just cracked it

@cd.artist.delete(@artist)

this seems to working nicely.

---

<div class="post-metadata">

**Author:** ![hiddenhippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@hiddenhippo](https://www.ruby-forum.com/u/hiddenhippo)\
**Post date:** [January 9, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/deleting-habtm/125522/3 "2008-01-09T22:37:41Z")

</div>

or it appears that you can

@cd.artists.clear

then i can rebuild the association again
