Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX Empty fields on SQLQuery->aggregate() with alias
Breaks Postgres otherwise, because it produces a "SELECT *, <field> ... " statement without putting all fields into the GROUP BY.
- Loading branch information
6d59257
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chillu Did you ever get something like this? ...see below:
mssql_query(): message: Column "SiteTree_Live.Sort" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
This most likely happens with PostgreSQL as well. You can check this by simply using a
<% cached 'something', List(Page).max(LastEdited) %>
block in the template. It will try querying for the aggregate and fail.e53280c seems to have introduced the ability to sort an aggregate.
DataQuery::initialiseQuery()
will add "Sort" as a default sorting on all queries to Page (SiteTree::$default_sort), but it won't add a GROUP BY automatically, thus causing the error. MSSQL complains if you sort an aggregate without specifying a GROUP BY clause. Seems like these template aggregates don't need any sorting or grouping anyway, so we could probably remove those.Thoughts?
EDIT: Proposed fix in this pull request: #1712