Skip to content

Instantly share code, notes, and snippets.

@jaz303
Last active January 1, 2016 05:38
Show Gist options
  • Save jaz303/8099432 to your computer and use it in GitHub Desktop.
Save jaz303/8099432 to your computer and use it in GitHub Desktop.
class Foo < ActiveRecord::Base
has_many :foo_bars
has_many :bars, :through => :foo_bars
end
class Bar < ActiveRecord::Base
end
class FooBar < ActiveRecord::Base
belongs_to :foo
belongs_to :bar
end
old_foo = Foo.find(id)
new_foo = Foo.create
# will attributes on the join models (FooBar) be copied or
# will they assume their default values?
new_foo.bars = old_foo.bars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment