I have model Register which marks the attendance of user based on department and group.Each user has a department and group.
Register Model
date:date , departmentid:string , groupid:integer , one:integer , two:integer
among the above fields "one and two" are time slots(say: from 9-14 , 14-18 ).Attendance are marked such that user belongs to current date , groupid , departmentid.So for same day there will be multiple entries with groupid ,departmentid and their attendance.
Sample Register table below
I want to find no. of users attented per day. currently i have tried
@register = Register.where(:date=>"2012-12-28").sum(:one)
it is getting well ,but i want to find like,
@register = Register.where(:date=>"2012-12-28").sum(:one , :two ,:three)
is it possible....
Thanks in advance.
How about this ?
class Register < AR:Base
...
def self.attendee_count(slot) # slot is :one or :two
scoped.group(:date ).sum(slot)
end
end
Register.where(:date => Date.today).attendee_count(:one)
Register.where(:date => Date.today, :departmentid => "DP14").attendee_count(:two)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With