I have a problem to group records by month or year. For exemple, I have this query:
records .select("strftime('%Y',date) as year")
.group("strftime('%Y',date)")
.order("strftime('%Y',date) DESC")
It work but it's a database specific code, for SQLite. So, when I pass my project on heroku it produce a bug. I can do a database specific code for each common database but it's uggly and complexe.
I view this solution :
group_by { |t| t.due_at.beginning_of_month }
but I think it's very expensive because I must to return all records in database before to group.
I also view this solution : http://ariejan.net/2007/01/12/rails-group-results-by-week-using-group_by
But I think than it's the same think.
Do you have a solution? Maybe with a Gem like squeel?