Retrieve the SQL query a scope would produce in ActiveRecord

Rails 3

User.active.to_sql

Rails 2

Use either the Edge Rider Show archive.org snapshot or fake_arel Show archive.org snapshot gem to get #to_sql backported to Rails 2.

If you don't want to use a gem for this, you can do this with vanilla Rails 2:

User.active.construct_finder_sql({})
Henning Koch