Over a million developers have joined DZone.

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
Topics:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}