title: Rails - Joining multiple tables
body: <p>I have the following models:</p>
  
  <pre><code>class Company &lt; ActiveRecord::Base
    has_many :price_movements
    has_many :goods_movements
  end
  
  class PriceMovement &lt; ActiveRecord::Base
    belongs_to :company
  end
  
  class GoodsMovement &lt; ActiveRecord::Base
     belongs_to :company
  end
  </code></pre>
  
  <p>I am trying to join everything together into an sql in the form of activerecord, but I'm not sure how to go about doing it because I'm relatively new to ROR.</p>
  
  <pre><code>select * from companies c
  
  inner join price_movements p
  on c.id = p.company_id
  
  inner join goods_movements g
  on c.id = g.company_id
  and g.date = p.date
  </code></pre>
  
  <p>The key problem for me is the second link where goods_movement date == price_movement date. 
  Can someone advice on whether there's any way to do it? </p>