aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-01 21:49:28 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-09-01 21:49:28 +0900
commit17faed96b48d6c6b0bd3e8f5c5b0117537fefa11 (patch)
treeedeecb518f7e4116764b03fa46d756c6eda9dfde
parent47200f502d4ae477545b3d7583f05db2df09c5ba (diff)
downloadrails-17faed96b48d6c6b0bd3e8f5c5b0117537fefa11.tar.gz
rails-17faed96b48d6c6b0bd3e8f5c5b0117537fefa11.tar.bz2
rails-17faed96b48d6c6b0bd3e8f5c5b0117537fefa11.zip
`add_reference` should respect column position for both reference id and type columns
Fixes #30496.
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb2
-rw-r--r--activerecord/test/cases/migration/column_positioning_test.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index 3b2c51ef94..788a455773 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -148,7 +148,7 @@ module ActiveRecord
end
def polymorphic_options
- as_options(polymorphic).merge(null: options[:null])
+ as_options(polymorphic).merge(options.slice(:null, :first, :after))
end
def index_options
diff --git a/activerecord/test/cases/migration/column_positioning_test.rb b/activerecord/test/cases/migration/column_positioning_test.rb
index 23414419dc..1c62a68cf9 100644
--- a/activerecord/test/cases/migration/column_positioning_test.rb
+++ b/activerecord/test/cases/migration/column_positioning_test.rb
@@ -52,6 +52,16 @@ module ActiveRecord
conn.change_column :testings, :second, :integer, after: :third
assert_equal %w(first third second), conn.columns(:testings).map(&:name)
end
+
+ def test_add_reference_with_positioning_first
+ conn.add_reference :testings, :new, polymorphic: true, first: true
+ assert_equal %w(new_id new_type first second third), conn.columns(:testings).map(&:name)
+ end
+
+ def test_add_reference_with_positioning_after
+ conn.add_reference :testings, :new, polymorphic: true, after: :first
+ assert_equal %w(first new_id new_type second third), conn.columns(:testings).map(&:name)
+ end
end
end
end