I've got a rails app that works fine in development (SQLite) but is throwing lots of errors when I've deployed it via Heroku, which uses PostgreSQL I gather.
the error message getting 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):
this is being thrown 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'd really like to keep the code clean so it works on both development and production DBs...can anyone shed some light?
I have 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.
Practice.group(Practice.col_list)
def self.col_list
Practice.column_names.collect {|c| "practices.#{c}"}.join(",")
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With