I am using the following code to group my active record relation by month. But as I extract attributes, I do not know how to get the date value as well.
This is my code:
books.group_by_month(:date).select("COUNT(*) as total, SUM(first_attribute) as fa").as_json
The output for the same is:
[
{"total"=>273, "fb"=>2864977652, "id"=>nil},
{"total"=>370, "fb"=>3882834096, "id"=>nil},
{"total"=>37, "fb"=>300460723, "id"=>nil}
]
How will I know which hash is for which month, how can I include the month data in my query as well?