Skip to content

Instantly share code, notes, and snippets.

@perezd
Created February 13, 2009 23:08
Show Gist options
  • Save perezd/64157 to your computer and use it in GitHub Desktop.
Save perezd/64157 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'activerecord'
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:username => 'root',
:database => 'craigslist'
)
class ActiveRecord::ConnectionAdapters::MysqlAdapter
# this will display barf out the sql right before its processed by the
# adapter
def execute_with_observant(sql, name = nil)
puts sql
execute_sql_call(sql, name) # master
end
# wrap my observant function around the execution process
alias_method :execute_sql_call, :execute
alias_method_chain :execute, :observant
end
# our test class
class Location < ActiveRecord::Base
end
# proof is in the pudding.
Location.all(:group => :name, :conditions => {:name => 'monkey'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment