提交 f5f7beb3 编写于 作者: J Jeremy Kemper

r3613@asus: jeremy | 2005-09-26 22:25:04 -0700

 Handle sequence reset for empty tables and models with custom primary keys.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2357 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 16978516
*SVN*
* Clean up Fixtures.reset_sequences for PostgreSQL. Handle tables with no rows and models with custom primary keys. #2174 [jay@jay.fm]
* Improve error message when nil is assigned to an attr which validates_size_of within a range. #2022 [Manuel Holtgrewe <purestorm@ggnore.net>]
* Make update_attribute use the same writer method that update_attributes uses.
......
......@@ -252,9 +252,9 @@ def self.reset_sequences(connection, table_names)
table_names.flatten.each do |table|
if table_class = table.to_s.classify.constantize rescue nil
pk = table_class.columns_hash[table_class.primary_key]
if pk and pk.name == 'id' and pk.type == :integer
if pk and pk.type == :integer
connection.execute(
"SELECT setval('#{table}_id_seq', (SELECT MAX(id) FROM #{table}), true)",
"SELECT setval('#{table}_#{pk.name}_seq', (SELECT COALESCE(0, MAX(#{pk.name}))+1 FROM #{table}), false)",
'Setting Sequence'
)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册