提交 f25f5336 编写于 作者: Y Yves Senn

Merge pull request #10505 from patricksrobertson/bigserial_id_not_identifying_pk

Handle other pk types in PostgreSQL gracefully.

Closes #10505.

- rebased
- test slightly modified
* Allow the PostgreSQL adapter to handle bigserial pk types again.
Fixes #10410.
*Patrick Robertson*
* Deprecate joining, eager loading and preloading of instance dependent * Deprecate joining, eager loading and preloading of instance dependent
associations without replacement. These operations happen before instances associations without replacement. These operations happen before instances
are created. The current behavior is unexpected and can result in broken are created. The current behavior is unexpected and can result in broken
......
...@@ -12,7 +12,7 @@ def visit_AddColumn(o) ...@@ -12,7 +12,7 @@ def visit_AddColumn(o)
def visit_ColumnDefinition(o) def visit_ColumnDefinition(o)
sql = super sql = super
if o.primary_key? && o.type == :uuid if o.primary_key? && o.type != :primary_key
sql << " PRIMARY KEY " sql << " PRIMARY KEY "
add_column_options!(sql, column_options(o)) add_column_options!(sql, column_options(o))
end end
......
...@@ -219,3 +219,29 @@ def test_primary_key_method_with_ansi_quotes ...@@ -219,3 +219,29 @@ def test_primary_key_method_with_ansi_quotes
end end
end end
end end
if current_adapter?(:PostgreSQLAdapter)
class PrimaryKeyBigSerialTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
class Widget < ActiveRecord::Base
end
setup do
@connection = ActiveRecord::Base.connection
@connection.create_table(:widgets, id: :bigserial) { |t| }
end
teardown do
@connection.drop_table :widgets
end
def test_bigserial_primary_key
assert_equal "id", Widget.primary_key
assert_equal :integer, Widget.columns_hash[Widget.primary_key].type
widget = Widget.create!
assert_not_nil widget.id
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册