ruby - How to Convert SQL Query to Rails Active Record Query -
query statement
select * timetables user_id in (select user_id timetables group user_id having count(*) > 1)
i don't want use find_by_sql. because find_by_sql returns array.
i want use mixture of (.where, .group, .having...)
help me...
the problem approach result of subquery interpreted ruby, not mysql, drastically slowing down performance, here go:
timetable.where(user_id: timetable.group(:user_id) .having('count(*) > 1') .pluck(:user_id)) #⇒ timetable::friendlyidactiverecordrelation < activerecord::relation
Comments
Post a Comment