我有这个代码
User.find(:all, :limit => 10, :joins => :user_points,
:select => "users.*, count(user_points.id)", :group =>
"user_points.user_id")
生成以下sql
SELECT users.*, count(user_points.id)
FROM `users`
INNER JOIN `user_points`
ON user_points.user_id = users.id
GROUP BY user_points.user_id
LIMIT 10
是否可以使用 LEFT JOIN 而不是 INNER JOIN 以外的方式User.find_by_sql
并手动输入查询?
你可以试试这个
User.find(:all, limit: 10,
joins: "LEFT JOIN `user_points` ON user_points.user_id = users.id" ,
select: "users.*, count(user_points.id)",
group: "user_points.user_id")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)