diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-03 03:36:00 -0800 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-03 03:36:00 -0800 |
commit | 2e902d52ebc70a121ef49cc042672b4facab16fa (patch) | |
tree | 44c9317e5f93756cf53a9eae938637aa01d0872a /activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | |
parent | 75981a920845c59f4e6993cc6fdaf67ed54dda40 (diff) | |
parent | f3470b08c9f72da56462f7857ef49501cb5f3201 (diff) | |
download | rails-2e902d52ebc70a121ef49cc042672b4facab16fa.tar.gz rails-2e902d52ebc70a121ef49cc042672b4facab16fa.tar.bz2 rails-2e902d52ebc70a121ef49cc042672b4facab16fa.zip |
Merge pull request #3833 from kennyj/fix_3678-3
Use show create table (fix 3678: third time).
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 11 |
1 files changed, 8 insertions, 3 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 7f5ddf77d6..4d2c80356d 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -499,9 +499,14 @@ module ActiveRecord # Returns a table's primary key and belonging sequence. def pk_and_sequence_for(table) - execute_and_free("SHOW INDEX FROM #{quote_table_name(table)} WHERE Key_name = 'PRIMARY'", 'SCHEMA') do |result| - keys = each_hash(result).map { |row| row[:Column_name] } - keys.length == 1 ? [keys.first, nil] : nil + execute_and_free("SHOW CREATE TABLE #{quote_table_name(table)}", 'SCHEMA') do |result| + create_table = each_hash(result).first[:"Create Table"] + if create_table.to_s =~ /PRIMARY KEY\s+\((.+)\)/ + keys = $1.split(",").map { |key| key.gsub(/`/, "") } + keys.length == 1 ? [keys.first, nil] : nil + else + nil + end end end |