diff options
author | kennyj <kennyj@gmail.com> | 2011-10-31 22:53:47 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2011-11-06 02:15:47 +0900 |
commit | fb0bf3c984fb088b5e436b25e6e5ae042e99c523 (patch) | |
tree | 9058ff89d79a8d0833d02ce2be3e5450c6fadea0 /activerecord/lib/active_record/connection_adapters | |
parent | cb06727b6cb7310808f5b9ce1bf254055806ba80 (diff) | |
download | rails-fb0bf3c984fb088b5e436b25e6e5ae042e99c523.tar.gz rails-fb0bf3c984fb088b5e436b25e6e5ae042e99c523.tar.bz2 rails-fb0bf3c984fb088b5e436b25e6e5ae042e99c523.zip |
Fixed an issue id false option is ignored on mysql/mysql2 (fix #3440)
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index dd573ba569..e2075225f0 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -496,8 +496,17 @@ module ActiveRecord # Returns a table's primary key and belonging sequence. def pk_and_sequence_for(table) - execute_and_free("DESCRIBE #{quote_table_name(table)}", 'SCHEMA') do |result| - keys = each_hash(result).select { |row| row[:Key] == 'PRI' }.map { |row| row[:Field] } + sql = <<-SQL + SELECT t.constraint_type, k.column_name + FROM information_schema.table_constraints t + JOIN information_schema.key_column_usage k + USING (constraint_name, table_schema, table_name) + WHERE t.table_schema = DATABASE() + AND t.table_name = '#{table}' + SQL + + execute_and_free(sql, 'SCHEMA') do |result| + keys = each_hash(result).select { |row| row[:constraint_type] == 'PRIMARY KEY' }.map { |row| row[:column_name] } keys.length == 1 ? [keys.first, nil] : nil end end |