When a database query cannot be described using Ruby on Rails’ short ActiveRecord syntax, consider building your queries using Arel instead of going for raw SQL strings.
This has the following advantages:
"users"."email" instead of
email in your queries helps you be future-proof by making queries that won’t break when you merge queries together or add columns with conflicting names.
"users"."email" ASC instead of
email asc. This makes it easier to search through logs and can help caching mechanisms.