aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/fixtures.rb4
2 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index e40c130b2d..0832ac3e16 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*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.
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 50e45e10e6..eb97c0f469 100755
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -252,9 +252,9 @@ class Fixtures < Hash
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