class Foo < ActiveRecord::Base
has_many :foo_bar_selections
has_many :bars, :through => :foo_bar_selections
end
class FooBarSelection < ActiveRecord::Base
belongs_to :foo
belongs_to :bar
end
class Bar < ActiveRecord::Base
has_many :foo_bar_selections
has_many :foos, :through => :foo_bar_selections
end
bar_old = Bar.create :name => "old"
bar_new = Bar.create :name => "new"
foo = Foo.create :baz => "old", :bars => [bar_old]
foo.baz
foo.bars
foo.baz = "new"
foo.bars = [bar_new]
foo.reload
foo.baz
foo.bars