Created
February 13, 2009 23:08
-
-
Save perezd/64157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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