diff options
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 65faa80065..5242151736 100755 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -440,6 +440,16 @@ module ActiveRecord variables.first['Value'] unless variables.empty? end + # Returns a table's primary key and belonging sequence. + def pk_and_sequence_for(table) #:nodoc: + table_desc_result = execute("describe #{table}") + keys = [] + execute("describe #{table}").each_hash do |h| + keys << h["Field"]if h["Key"] == "PRI" + end + keys.length == 1 ? [keys.first, nil] : nil + end + private def connect encoding = @config[:encoding] |