Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Extract Sql From Active Record

DZone's Guide to

Extract Sql From Active Record

·
Free Resource
// 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
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}