Forum: Ruby on Rails many to many and delete question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Allen W. (Guest)
on 2008-12-15 03:32
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

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

Sijo k. (Guest)
on 2008-12-15 06:54
But the above wont delete the bar record But delete only the
This topic is locked and can not be replied to.