I want to create an array of elements created every hour, every day.
I track how people feel, so my model is called TrackMood
It only has a column named mood
and timestamps.
If i do
TrackMood.where(mood: "good").group("hour(created_at)").count
I get something like {11 => 4, 12 => 2, 13 => 2, 15 => 1}
I have 2 problems here
1 How to add a day to this so that it doesnโt just add elements created yesterday at 11 oโclock to elements added today at 11 oโclock?
2 How can I make sure it says 0
for hours when nothing is created?
source share