1

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?

Dougui
  • 7,142
  • 7
  • 52
  • 87
  • 1
    If you are sticking with Heroku long term you should seriously consider using Postgres on you development machine. – fatfrog Feb 18 '12 at 11:32
  • Try here: http://stackoverflow.com/questions/1769361/postgresql-group-by-different-from-mysql And here: http://stackoverflow.com/questions/3512286/elegant-postgresql-group-by-for-ruby-on-rails-activerecord – fatfrog Feb 18 '12 at 11:37
  • I already seen this posts but I think than there is not a better solution. – Dougui Feb 18 '12 at 12:55
  • Have to agree with @fatfrog that if you're using Heroku you should really be using Postgres in your development environment. It might seem like a pain to setup but it will really save you lots of time and headaches. – Pete Apr 10 '12 at 10:40

0 Answers0