title: how to merge an arel object into an ActiveRecord::Relation chain?
body: <p>I know how to convert the following into using strictly Arel methods, instead of mixed sql/string, but I dont' know how to merge the resulting arel object into an ActiveRecord::Relation so I can chain more AR::Relation methods on it. </p>
  
  <p>I got the following very helpful answer to my previous question:</p>
  
  <pre><code>class Address &lt; ActiveRecord::Base
    scope :anywhere, lambda{|search|
      attrs = [:line1, :line2, :city, :state, :zip]
      where(attrs.map{|attr| 
        "addresses.#{attr} LIKE :search"
      }.join(' OR '), search: "#{search}%").order(*attrs) 
    }
  end
  
  Person.joins(:address).merge(Address.anywhere(query_term))
  </code></pre>
  
  <p>I tried to do something like this:</p>
  
  <pre><code>class Address &lt; ActiveRecord::Base
    scope :anywhere, lambda{|search|
      addr_arel = Address.arel_table
      attrs = [:line1, :line2, :city, :state, :zip]
      attrs.inject {|attr| 
        q = addr_arel[attr].match("%#{search}%") unless q
        q = q.or(addr_arel[attr].match("%#{search}%")
      }
    }
  end
  </code></pre>
  
  <p>But I end up with an arel object and I don't know how to merge it with the following ActiveRecord::Relation:</p>
  
  <p>Person.joins(:address).merge(Address.anywhere(query_term))</p>
  
  <p>(not to mention the inject is not very elegant either - how do I improve that?)</p>