限制活动记录查询的特定部分
Limit specific part of active record query
我很难弄清楚如何限制查询结果的正确部分。基本上我试图让所有符合条件的用户以及当前用户。
我的代码是:
@users = users.where(id: current_user).or(users.where('email LIKE ?', "%#{user_email}%")).limit(10)
出现此问题是因为如果匹配用户太多,当前用户可能不在列出的十个用户中。
感谢您的任何建议。
@users = users.
where(id: current_user).
or(users.where('email LIKE ?', "%#{user_email}%")).
order(Arel.sql("case when talents.id = #{current_user} then 1 else 2 end")).
limit(10)
使用此 order by 子句,您使匹配 id 的行显示结果的第一行
我很难弄清楚如何限制查询结果的正确部分。基本上我试图让所有符合条件的用户以及当前用户。
我的代码是:
@users = users.where(id: current_user).or(users.where('email LIKE ?', "%#{user_email}%")).limit(10)
出现此问题是因为如果匹配用户太多,当前用户可能不在列出的十个用户中。
感谢您的任何建议。
@users = users.
where(id: current_user).
or(users.where('email LIKE ?', "%#{user_email}%")).
order(Arel.sql("case when talents.id = #{current_user} then 1 else 2 end")).
limit(10)
使用此 order by 子句,您使匹配 id 的行显示结果的第一行