Many to many and delete question

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


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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs