Skip to content

Instantly share code, notes, and snippets.

@apolzon
Created March 6, 2012 17:55
Show Gist options
  • Select an option

  • Save apolzon/1987767 to your computer and use it in GitHub Desktop.

Select an option

Save apolzon/1987767 to your computer and use it in GitHub Desktop.
require 'active_record'
require 'active_record/base'
module ActiveRecord
module ConnectionAdapters
class Mysql2Adapter < AbstractAdapter
def pk_and_sequence_for(table) #:nodoc:
puts "!!!"
keys = []
result = execute("SHOW CREATE TABLE #{quote_table_name(table)}", 'SCHEMA')
ct = ''
result.each(:symbolize_keys => true, :as => :hash) { |row| ct << row[:"Create Table"] }
if ct.to_s =~ /PRIMARY KEY\s+\((.+)\)/
keys = $1.split(",").map { |key| key.gsub(/`/, "") }
keys.length == 1 ? [keys.first, nil] : nil
else
nil
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment