Method to return sum of multiple columns in Rails ActiveRecord Model -
i'm new rails , activerecord , wondering if there straightforward way below without having create complicated sql group queries , passing params.
i have model lineproduction columns line_date (date), line_1 (integer), line_2(integer), line_3(integer).
i create method in model return daily_total of lines grouped date - daily_total(line_date) can return value in table report each row of month. eg.
line_date line_1 line_2 line_3 daily_total
thanks!
you can take @ gem https://github.com/ankane/groupdate
lineproduction.group_by_date(:line_date).count # { # 2016-02-01 00:00:00 utc => 50, # 2013-02-02 00:00:00 utc => 100, # 2013-02-03 00:00:00 utc => 34 # }
Comments
Post a Comment