How to delete from a HABTM table?

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

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