Skip to content

Instantly share code, notes, and snippets.

View rupurt's full-sized avatar
🏠
Working from home

Alex Kwiatkowski rupurt

🏠
Working from home
View GitHub Profile
@rupurt
rupurt / left_join_arel_example.rb
Created May 2, 2016 13:51 — forked from mildmojo/left_join_arel_example.rb
LEFT JOIN in ARel for ActiveRecord in Ruby on Rails
# Here's a contrived example of a LEFT JOIN using ARel. This is an example of
# the mechanics, not a real-world use case.
# == DEFINITIONS
# - A Taxi is a car for hire. A taxi has_many :passengers.
# - A Passenger records one person riding in one taxi one time. It belongs_to :taxi.
class Taxi < ActiveRecord::Base
# This scope LEFT JOINs the Passenger table. You might use this if you wanted
# to select taxis by a set of taxi and passenger IDs (as with the