Assuming I have an ActiveRecord::Base subclass User
and table users
, I am not sure how to write this query in ActiveRecord:
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
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?
Thanks!