radar/forem — Issue #153: Fix for #150 breaks on some versions of postgres
Author: jgadbois
Created: 2012-02-20 15:26:51+00:00
State: open

In my development environment

```
PG::Error: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ..."hidden" = 'f' ORDER BY forem_topics.pinned DESC, forem_post...
^
: SELECT DISTINCT forem_topics.id, forem_topics.* FROM "forem_topics" INNER JOIN "forem_posts" ON "forem_posts"."topic_id" = "forem_topics"."id" WHERE "forem_topics"."forum_id" = 1 AND "forem_topics"."hidden" = 'f' ORDER BY forem_topics.pinned DESC, forem_posts.created_at DESC, forem_topics.id LIMIT 20 OFFSET 0
```

I had some other similar queries that worked previously break when I upgraded to Rails 3.2.

This is going to be a problem for the fix for #150, because if we add the created_at date back into the select clause, then duplicate topics will reappear (1 row per unique created_at date).

One potential solution is to add ``` belongs_to :topic, :touch=>true ``` and just order by the topic updated_at. If that works for you I can implement now.