DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Extract Sql From Active Record
// This method extends ActiveRecord and return the sql generated
// For instance: City.view_sql(6) will return "select * from cities where id=6"
// you can use all ActiveRecord stuff (includes, order, conditions....)
module ActiveRecord
class Base
class << self
def view_sql(*args)
options = args.extract_options!
validate_find_options(options)
set_readonly_option!(options)
construct_finder_sql(options)
end
end
end
end





