activerecord - Select sum and dynamic where statement query in Rails 4 -


i have below statement in controller , want know how rewrite in rails 4

entry.find(:all, :conditions => [@conditions.keys.join(" , "), *@conditions.values],:group => "user_id",                                 :select => "sum(time_spent) total_spent") 

the condition has user_id information in "user_id=?".

the statement trying find entry particular user id , sum time spent user id , group user id.

for example can use it

realations = entry.where(user_id: [1, 2, 3]).select("sum(time_spent) total_spent").group(:user_id) 

after have relation can work

realations.each |i|   puts i.total_spent end 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -