Skip to content

Instantly share code, notes, and snippets.

@glv
Created November 17, 2010 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glv/703997 to your computer and use it in GitHub Desktop.
Save glv/703997 to your computer and use it in GitHub Desktop.
USE INDEX with Active Record finders for Rails 3
# for background, see http://m.onkey.org/use-index-with-active-record-finders
# and http://twitter.com/#!/dougalcorn/status/4963159878139904
from = "#{quoted_table_name} USE INDEX(index_activities_on_created_at_and_country_id)"
Activity.from(from).where('created_at >= ? AND country_id = ?', 10.days.ago, 79).all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment