For general knowledge and entertainment purposes I am trying to add some behavoiur to Rails. What I am looking for is simply to run a Mysql "EXPLAIN" statement before every select statement that Rails runs. I think this should work ok but I am getting the error:
/usr/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/module/aliasing.rb:32:in alias_method': undefined method
select_with_explain' for class `ActiveRecord::ConnectionAdapters::MysqlAdapter' (NameError)
This class is located in the initializers dir. Here is the code:
module Explanifier
def self.included(base)
base.class_eval do
extend ClassMethods
alias_method_chain :select, :explain
end
end
module ClassMethods
def select_with_explain(sql, name = nil)
puts "testing!!!"
execute('EXPLAIN ' + sql, name)
select_without_explain(sql, name)
end
end
end
class ActiveRecord::ConnectionAdapters::MysqlAdapter
include Explanifier
end
Can someone explain what I am missing here?