add_reference should respect column position for both reference id and type columns

Fixes #30496.
This commit is contained in:
Ryuta Kamizono 2017-09-01 21:49:28 +09:00
parent 47200f502d
commit 17faed96b4
2 changed files with 11 additions and 1 deletions

@ -148,7 +148,7 @@ def as_options(value)
end
def polymorphic_options
as_options(polymorphic).merge(null: options[:null])
as_options(polymorphic).merge(options.slice(:null, :first, :after))
end
def index_options

@ -52,6 +52,16 @@ def test_change_column_with_positioning
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