title: Rails get value from join table
body: <p>I have models named <code>country</code>, <code>city</code> and <code>province</code>.</p>
  
  <pre><code>Country
  has_many: cities
  
  City
  has_many :provinces
  belongs_to :country
  
  Province
  belongs_to :city
  </code></pre>
  
  <p>This model has the same columns <code>name</code>, <code>lat</code> and <code>long</code></p>
  
  <p>So when I get <code>params[:name]</code>, I would like to search on three models in one query with join to find the relevant record. </p>
  
  <p>For instance if it is France it will find it in country etc..</p>
  
  <p>Is this possible?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I tried;</p>
  
  <pre><code>Country.all.joins(city: :province).where("cities.name = ? or provinces.name = ?", params[:name])
  </code></pre>
  
  <p>But this returns the country. I would like to find if it is country get lat and long, if its city get lat long of the city and if it is province get lat and long of the province.</p>