Skip to content

Instantly share code, notes, and snippets.

@sandheepg
Last active March 8, 2017 08:09
Show Gist options
  • Save sandheepg/662150f43587ed078874d7cad6cc32cb to your computer and use it in GitHub Desktop.
Save sandheepg/662150f43587ed078874d7cad6cc32cb to your computer and use it in GitHub Desktop.
Retrieve SQL query in Rails 2.x

The method is construct_finder_sql(options) (lib/active_record/base.rb:1681) You will have to use send because it is private.

sql = Item.send :construct_finder_sql, :select => :all, :include => [:categories, :prices], :conditions => conditions

sql = ActionType.send :construct_finder_sql, :select => 'hosted, top_action_type, count(*) as count', :group => 'hosted, top_action_type'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment