You can take advantage of find_by_sql and to_json
json_records = Arel::Table.find_by_sql(query.to_sql).to_json
Then you can extract your results like
result = JSON.parse json_records
There are several ways to convert ActiveRecord
objects to hash
. This is just my personal preference.