Module: ActiveRecord::Extensions::FinderOptions::ClassMethods

Defined in:
lib/ar-extensions/finder_options.rb

Instance Method Summary collapse

Instance Method Details

#finder_sql_to_string(options) ⇒ Object

Return a string containing the SQL used with the find(:all) The options are the same as those with find(:all)

Additional parameter of :force_eager_load forces eager loading even if the

column is not referenced.

 sql = Contact.finder_sql_to_string(:include => :primary_email_address)
 Contact.find_by_sql(sql + 'USE_INDEX(blah)')


77
78
79
80
81
# File 'lib/ar-extensions/finder_options.rb', line 77

def finder_sql_to_string(options)
  select_sql = self.send(
    (use_eager_loading_sql?(options) ? :finder_sql_with_included_associations : :construct_finder_sql),
    options.reject{|k,v| k == :force_eager_load}).strip
end