Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 #=> "old"
- foo.bars #=> [#<Bar id: 1, name: "old">]
- foo.baz = "new"
- foo.bars = [bar_new]
- foo.reload
- foo.baz #=> "old"
- foo.bars #=> [#<Bar id: 2, name: "new">]
- # variable 'baz' does not get saved, but 'bars' does
- # QUESTION: is there any way to prevent 'bars' from getting saved?
Add Comment
Please, Sign In to add comment