Last active
August 29, 2015 14:24
-
-
Save devhero/93c3968808b54ad5f870 to your computer and use it in GitHub Desktop.
arel getting started
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# equivalent constructors of arel table | |
model = Arel::Table.new 'model_table_name' | |
model = Arel::Table.new :model_table_name | |
model = Model.arel_table | |
# prepare arel query | |
model_query = model.project(model[Arel.star]).where(model[:id].lte(20)) | |
# executing query and obtains an array of Model objects | |
model_list = Model.find_by_sql model_query | |
# executing query obtains an array of hashes | |
resultset = ActiveRecord::Base.connection.execute model_query | |
# references | |
http://blog.donwilson.net/2011/11/constructing-a-less-than-simple-query-with-rails-and-arel/ | |
https://github.com/rails/arel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment