From 99910dddf28faac31d6a3d4800460f1bc308bb83 Mon Sep 17 00:00:00 2001 From: Sam DeCesare Date: Mon, 9 Apr 2018 17:35:33 -0700 Subject: Fix .new with multiple through associations This fixes a bug with building an object that has multiple `has_many :through` associations through the same object. Previously, when building the object via .new, the intermediate object would be created instead of just being built. Here's an example: Given a GameBoard, that has_one Owner and Collection through Game. The following line would cause a game object to be created in the database. GameBoard.new(owner: some_owner, collection: some_collection) Whereas, if passing only one of those associations into `.new` would cause the Game object to be built and not created in the database. Now the above code will only build the Game object, and not save it. --- activerecord/test/schema/schema.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'activerecord/test/schema') diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 350113eaab..274879d4af 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -364,6 +364,19 @@ ActiveRecord::Schema.define do t.integer :follower_id end + create_table :games, force: true do |t| + t.integer :game_owner_id + t.integer :game_collection_id + end + + create_table :game_boards, force: true do |t| + t.integer :game_id + end + + create_table :game_collections, force: true + + create_table :game_owners, force: true + create_table :goofy_string_id, force: true, id: false do |t| t.string :id, null: false t.string :info -- cgit v1.2.3