Retrieve the SQL query a scope would produce in ActiveRecord

Updated . Posted . Visible to the public.

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
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2011-04-07 16:09)