Tables

users = Arel::Table.new(:users)
users = User.arel_table  # ActiveRecord model

Fields

users[:name]
users[:id]

where (restriction)

users.where(users[:name].eq('amy'))
# SELECT * FROM users WHERE users.name = 'amy'

select (projection)

users.project(users[:id])
# SELECT users.id FROM users

join

users.join(photos)
users.join(photos, Arel::Nodes::OuterJoin).on(users[:id].eq(photos[:user_id]))

limit / offset

users.take(5) # => SELECT * FROM users LIMIT 5
users.skip(4) # => SELECT * FROM users OFFSET 4

Aggregates

users.project(users[:age].sum) # .average .minimum .maximum
users.project(users[:id].count)
users.project(users[:id].count.as('user_count'))

order

users.order(users[:name])

With ActiveRecord

User.arel_table
User.where(id: 1).arel

Reference