Skip to content

Instantly share code, notes, and snippets.

@zhangxu
Created August 12, 2014 03:13
Show Gist options
  • Save zhangxu/b8428f31267f6c5c6907 to your computer and use it in GitHub Desktop.
Save zhangxu/b8428f31267f6c5c6907 to your computer and use it in GitHub Desktop.
ActiveRecord Raw SQL
@results = []
ActiveRecord::Base.connection.select_all(
ActiveRecord::Base.send(:sanitize_sql_array,
["select * from events where area_type = ? and area_id = ?", 'parcel', '1'])
).each do |record|
# instead of an array of hashes, you could put in a custom object with attributes
@results << {id: record["id"], category: record["category"]}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment