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

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -