title: rails union hack, how to pull two different queries together
body: <p>I have a query which searches two separate fields in the same table... looking for locations which are most likely a specific city, but could also be a country... ie the need for two fields.</p>
  
  <p>Table looks like:</p>
  
  <pre><code>Country    City
  
  Germany    Aachen
  USA        Amarillo
  USA        Austin
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Keyword   Sideinfo
  
  Aachen    Germany
  USA       Country
  Austin    USA
  Germany   Country 
  </code></pre>
  
  <p>Basically I'm wondering if there is a more concise way to do this because I had to use two separate queries then add them together, sort them, etc. (which works fine):</p>
  
  <pre><code>  def self.ajax(search)
      countries = Location.find(:all, :select=&gt; 'country AS keyword,  "Country" AS sideinfo', :joins =&gt; :hotels, :conditions =&gt; [ 'hotels.email IS NOT NULL AND country LIKE ?', "#{search}%" ], :group =&gt; :country )
      cities = Location.find(:all, :select=&gt; 'city AS keyword, country AS sideinfo', :joins =&gt; :hotels, :conditions =&gt; [ 'hotels.email IS NOT NULL AND city LIKE ?', "#{search}%" ], :group =&gt; :city )
      out = cities + countries
      out = out.sort { |a,b| a.keyword &lt;=&gt; b.keyword }
      out.first(8)
    end
  </code></pre>
  
  <p>I couldn't find any information on how to unions using ActiveRecord...</p>