title: Multi level joins in rails 4
body: <p>I want to make this query in rails 4   </p>
  
  <pre><code>select r.region_id, r.region_name from countries c, zones z, regions r where c.country_id = $country_id (pass as parameter) and c.country_id = z.zone_id and z.subzone_id = r.region_id
  </code></pre>
  
  <p>Models :</p>
  
  <pre><code> #Country.rb
  class Country &lt; ActiveRecord::Base
    has_one :place, foreign_key: :place_id
    has_many :zones , foreign_key: :place_id
    has_many :subzones, :through =&gt; :zones
  end
  
  #Zone.rb
  class Zone &lt; ActiveRecord::Base
   belongs_to :place
   belongs_to :subzone, :class_name =&gt; 'Place' , :foreign_key =&gt; :subzone_id
  end
  
  #Region.rb
  class Region &lt; ActiveRecord::Base
    has_one :place , foreign_key: :place_id
  end
  
  #Place.rb
  class Place &lt; ActiveRecord::Base
    belongs_to :region, :foreign_key =&gt; :place_id
    has_many :zones, :foreign_key =&gt; :place_id
    has_many :subzones, :through =&gt; :zones
  end
  </code></pre>
  
  <p>I have tried this:</p>
  
  <pre><code>Country.joins(:zones).where("zone.subzone_id = regions.region_id AND country_id = ?",$country_id )
  </code></pre>
  
  <p>but got error as :</p>
  
  <pre><code>Java::JavaSql::SQLSyntaxErrorException: ORA-00904: "REGIONS"."REGION_ID": invalid identifier.....
  </code></pre>
  
  <p>Not sure how to load region in above query...</p>
  
  <p>Thanks in advance :-)</p>