Why am I getting a PG error on heroku when it works fine on my local rails environment?
I am getting the following error:
ReportsController#return_search (ActiveRecord::StatementInvalid) "PGError: ERROR: syntax error at or near \"FROM\"\nLINE 5: ...OUNT(contact_postalcards.id) AS postalcard_count, FROM \"cont...\n
It works fine locally, but when I push to heroku I get the error:
What do I need to change so it will work also on Postgres on Heroku?
@list = Contact.find :all,
:select => "companies.name AS co_name,
companies.id AS comp_id,
COUNT(contact_emails.id) AS email_count,
开发者_如何学JAVA COUNT(contact_calls.id) AS call_count,
COUNT(contact_letters.id) AS letter_count,
COUNT(contact_postalcards.id) AS postalcard_count",
:conditions => ['contact_emails.date_sent < ? and contact_emails.date_sent > ?',
report_end_date, report_start_date],
:joins => [
"LEFT JOIN companies ON companies.id = contacts.company_id",
"LEFT JOIN contact_emails ON contact_emails.contact_id = contacts.id",
"LEFT JOIN contact_letters ON contact_letters.contact_id = contacts.id",
"LEFT JOIN contact_postalcards ON contact_postalcards.contact_id = contacts.id",
"LEFT JOIN contact_calls ON contact_calls.contact_id = contacts.id"
],
#:group => "companies.id"
:group => "companies.name"
puts @list[0].attributes.inspect
From the errormessage:
AS postalcard_count, FROM
Drop this comma , in your query, it's your bug.
It looks like this was a PG specific so I changed the database structure altogether.
精彩评论