我正在尝试将此查询转换为 AREL:
SELECT users.* FROM users LEFT OUTER JOIN (
SELECT DISTINCT educations.user_id
FROM educations
INNER JOIN schools
ON educations.school_id = schools.id
WHERE schools.name = "school_name" ) AS x
ON users.id = x.user_id WHERE x.user_id IS null
我希望能够像这样链接这个查询:
class User < ActiveRecord::Base
def find_by_school(school_name)
...
end
end
myUser.find_by_school("school_name").where(...).joins(...)...etc
有任何想法吗?