I have a rails application that works fine in development (SQLite), but throws a lot of errors when I deployed it through Heroku, which uses PostgreSQL, which I am building.
error message returned:
ActionView::Template::Error (PGError: ERROR: column "practices.id" must appear in the GROUP BY clause or be used in an aggregate function: SELECT "practices".* FROM "practices" WHERE ("practices".activity_id = 1) AND ("practices"."created_at" BETWEEN '2011-01-01' AND '2011-01-31') GROUP BY DATE(created_at) ORDER BY created_at DESC):
it throws when I call the following:
def month_days_not_practiced(date = Date.today) p = practices.where(:created_at => date.at_beginning_of_month..date.at_end_of_month).group("DATE(created_at)").to_a.count days_in_month(date.year, date.month) - p end
I would very much like the code to be clean, so it works with both development bases and production ... can anyone shed some light?
I tried this:
def month_days_not_practiced(date = Date.today) p = practices.where(:created_at => date.at_beginning_of_month..date.at_end_of_month).group("practices.id, DATE(created_at)").to_a.count days_in_month(date.year, date.month) - p end
to no avail ...
TIA.
source share