bshaffer/redmine-assets-plugin — Issue #9: Invalid use of GROUP BY when using Postgres backend
Author: Simon143
Created: 2011-11-27 00:16:19+00:00
State: open

I'm running Redmine with a Postgres database, and the query in `types_for_project` is giving the following error because Postgres sticks to the standard use of `GROUP BY`:

ActiveRecord::StatementInvalid (PGError: ERROR: column "attachments.id" must appear in the GROUP BY clause or be used in an aggregate function
: SELECT "attachments".* FROM "attachments" LEFT JOIN messages ON messages.id = container_id AND container_type = 'Message' LEFT JOIN boards on board_id = boards.id LEFT JOIN issues ON issues.id = container_id AND container_type = 'Issue' LEFT JOIN issue_categories on issues.category_id = issue_categories.id LEFT JOIN versions ON versions.id = container_id AND container_type = 'Version' LEFT JOIN wiki_pages ON wiki_pages.id = container_id AND container_type = 'WikiPage' LEFT JOIN wikis on wiki_id = wikis.id LEFT JOIN documents ON documents.id = container_id AND container_type = 'Document' LEFT JOIN enumerations on documents.category_id = enumerations.id AND type='DocumentCategory' WHERE ((boards.project_id = 29) OR (issues.project_id = 29) OR (versions.project_id = 29) OR (wikis.project_id = 29) OR (documents.project_id = 29)) GROUP BY container_type):
vendor/plugins/redmine_assets_plugin/app/controllers/assets_controller.rb:67:in `types_for_project'
vendor/plugins/redmine_assets_plugin/app/controllers/assets_controller.rb:10:in `index'

I tried removing the group condition entirely but obviously that just produces an index page with a container type for every item that exists which isn't particularly helpful. One fix would be using `DISTINCT` instead, I'm giving that a go...