Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Arel cheatsheet

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Columns

posts[:id]
posts[:title]

Select

posts.project(:id, :title) #=> "SELECT id, title FROM posts"
posts.project(posts[:id], posts[:title]) #=> "SELECT `posts`.`id`, `posts`.`title` FROM `posts`"
posts.project(posts[Arel.star]) #=> "SELECT `posts`.`*` FROM `posts`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.