diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-09-27 01:51:05 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-09-27 01:51:05 +0000 |
commit | f5f7beb3692a2919943f44b10b29852b30f8fb1e (patch) | |
tree | 2453b1e0fe6180206d99d96da0c2ef16555d6ee2 /activerecord/lib/active_record | |
parent | 169785162c08eddf3fedd151fc655440e1511efd (diff) | |
download | rails-f5f7beb3692a2919943f44b10b29852b30f8fb1e.tar.gz rails-f5f7beb3692a2919943f44b10b29852b30f8fb1e.tar.bz2 rails-f5f7beb3692a2919943f44b10b29852b30f8fb1e.zip |
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
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/fixtures.rb | 4 |
1 files changed, 2 insertions, 2 deletions
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 |