title: How to write this query in activerecord?
body: <p>Assuming I have an ActiveRecord::Base subclass <code>User</code> and table <code>users</code>, I am not sure how to write this query in ActiveRecord:</p>
  
  <pre><code>SELECT *
  FROM (
      SELECT users.* 
      FROM   follows
      INNER JOIN users ON users.id = follows.following_id
      WHERE  username LIKE 'r%' AND follows.follower_id = 5717
      LIMIT 10
  
      UNION
  
      SELECT * 
      FROM   users 
      WHERE  username LIKE 'r%' 
      LIMIT 10
  ) AS users
  LIMIT 10
  </code></pre>
  
  <p>I am selecting from a custom generated table. How would I even start writing this query? Is this even possible? If so how, and if not, what are my alternatives?</p>
  
  <p>Thanks!</p>