I want to create a method for my Activity model that has many Practices called month_days_not_practiced which gives a count of the days in the current month that the Activity does not have any practices recorded for (note: days_in_month is a helper method):
def month_days_not_practiced(date = Date.today)
p = practices.where(:created_at => date.at_beginning_of_month..date.at_end_of_month).count
days_in_month - p
end
However, I want to return only one record per month day.
Can someone help me with my custom SQL (I think) please? I’m drawing a blank at the moment..
TIA!
Andy
Put this on the end of your query: