Q:

Is a double-level joins table possible? 

I have three tables, Show, Episode, and Character.  Each Show has_many Episodes and Characters. 
class Show < ActiveRecord::Base
  has_many :episodes
  has_many :characters

class Episode < ActiveRecord::Base
  belongs_to :show

class Character < ActiveRecord::Base
  belongs_to :show

I have a list of Characters.  What I want to do is order them by the date that their Show's second Episode aired on.  Episode has a uniquely named attribute called :air_date
So I would have to do a two-level joins table, something like:
@characters = Character.joins(:show)
                       .joins(:episodes)
                       .where(episodes: {number: 2})
                       .order(:air_date)

But ActiveRecord thinks I'm looking for Episodes associated with Characters, and of course that association doesn't exist. 
How can I return the Episodes associated with the Shows associated with a list of Characters?  Or is that even possible? 

A:

You should use this syntax (I assume air_date is an attribute of episodes):
Character.joins(show: :episodes)
         .where(episodes: {number: 2})
         .order('episodes.air_date ASC')

You should also be able to use AREL for that:
Character.joins(show: :episodes)
         .where(episodes: {number: 2})
         .order(Episode.arel_table[:air_date].asc)

If you want to load everything to memory you can use includes, preload or eager_load instead of joins
A complete explanation and examples can be found here.