Arguably, Arel was one of the biggest new features introduced in Rails 3. Arel simplifies building complex SQL statements using idiomatic Ruby.
Rel can be installed via npm:
npm install rel
We can then begin building a query:
users = new Rel.Table 'users'
If we want all users in our CMS we could use the
Rel really shines, however, when using several chained operators, including joins:
users.join(photos).on(users.column('id').eq(photos.column('user_id'))) # => SELECT * FROM users INNER JOIN photos ON users.id = photos.user_id
Have comments? Send a tweet to @TheChangelog on Twitter.
Subscribe to The Changelog Weekly – our weekly email covering everything that hits our open source radar.