Reputation: 1078
When a client hits my Rails app's API for data, I would like to pass back the query that generated the data with the data. I'm using Rails 2.
Right now I've edited the Rails mysql_adapter to put all queries in a global hash that has the user session as a key and the query as a value.
This is very hacky and probably not thread-safe.
Is there a better way?
Upvotes: 2
Views: 118
Reputation: 1037
You can use fake_arel gem to get the .to_sql
functionality into rails 2.
Upvotes: 1
Reputation: 10405
Don't know if it can help but you can whenever you want call to_sql
on an ActiveRecord object :
user = User.where(:id => 1)
user.to_sql # Outputs "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" = 1"
Upvotes: 4