title: Multi-dimensional JOINs with ActiveRecord and Sinatra
body: <p>I've recently broken out a single table into three separate tables and now am having trouble combining them into a list.</p>
  
  <p>I have a Venue
   - has many Orders
    - has many Items</p>
  
  <p>In an attempt to list all the orders and accompanying information from a Venue:</p>
  
  <p>app.rb</p>
  
  <pre><code>get "/:venue/orders" do
    @venue = Venue.find_by_handle(params[:venue])
    @orders = Order.joins(:venue).where(:venues =&gt; {:handle =&gt; @venue.handle})
    @items = Item.joins(:order).where(:orders =&gt; {:id =&gt; @orders.id})
    erb :"venue/index"
  end
  </code></pre>
  
  <p>venue/index.erb</p>
  
  <pre><code>&lt;% @orders.each do |order| %&gt;
    &lt;h3&gt;Order &lt;%= order.id %&gt;&lt;/h3&gt;
    &lt;h4&gt;&lt;%= @customer.email %&gt;&lt;/h4&gt;
    &lt;% @items.each do |item| %&gt;
      &lt;h5&gt;&lt;%= item.quantity %&gt; x &lt;%= item.item %&gt;&lt;/h5&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>models.rb</p>
  
  <pre><code>class Order &lt; ActiveRecord::Base
    belongs_to :venue
    belongs_to :customer
  
    has_many :items
  
    validates :venue_id, presence: true
  end
  
  class Item &lt; ActiveRecord::Base
    belongs_to :order
  
    validates :order_id, :presence =&gt; true
    validates :quantity, :presence =&gt; true
    validates :item, :presence =&gt; true
  end
  
  class Customer &lt; ActiveRecord::Base
    has_many :orders
  
    validates :email, :presence =&gt; true
  end
  
  class Venue &lt; ActiveRecord::Base
    has_many :customers, :through =&gt; :orders
    has_many :orders
  
    validates :name, :presence =&gt; true
    validates :handle, :presence =&gt; true, :uniqueness =&gt; true
  end
  </code></pre>
  
  <p>I receive a NoMethodError for 'id' and understand because i'm not looking at a specific order. How do I go about querying for the necessary items?</p>