lml / commontator

A Rails engine for comments
MIT License
353 stars 99 forks source link

Bug: Nested Comments - PG::GroupingError: ERROR: column "commontator_comments.created_at" must appear in the GROUP BY clause or be used in an aggregate function #138

Closed aurora-a-k-a-lightning closed 5 years ago

aurora-a-k-a-lightning commented 5 years ago
rails 5.2.3
commontator: 6.0.0.pre.2
postgres 11

Hi there!

We are attempting to use the nested comments feature by setting the config to :i for comment_reply_style and we are getting this error:

image

ActiveRecord::StatementInvalid in Practices#show
Showing /Users/app/views/commontator/threads/_show.html.erb where line #11 raised:

ActiveRecord::StatementInvalid in Practices#show
Showing /Users/app/views/commontator/threads/_show.html.erb where line #11 raised:

PG::GroupingError: ERROR:  column "commontator_comments.created_at" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...UP BY "commontator_comments"."parent_id" ORDER BY "commontat...
                                                             ^
: SELECT COUNT(*) AS count_all, "commontator_comments"."parent_id" AS commontator_comments_parent_id FROM "commontator_comments" WHERE "commontator_comments"."thread_id" = $1 AND "commontator_comments"."parent_id" = $2 GROUP BY "commontator_comments"."parent_id" ORDER BY "commontator_comments"."created_at" ASC
Extracted source (around line #11):
9
10
11
12
13
14

  can_edit = thread.can_be_edited_by?(user)
  comments = thread.paginated_comments(page, nil, show_all)
  nested_comments = thread.nested_comments_for(user, comments, show_all)
%>

<div id="commontator-thread-<%= thread.id %>-show" class="show hidden">

Trace of template inclusion: app/views/commontator/shared/_thread.html.erb, app/views/practices/show.html.erb

Has anyone else ran into this yet?

Any help will be appreciated :smile:
Thank you!

Dantemss commented 5 years ago

Thanks for the bug report. Should be a simple fix: changing https://github.com/lml/commontator/blob/7701c86ea9650393f2ca2711bf59dff16f1a4c86/app/models/commontator/thread.rb#L93 to use filtered_comments instead of ordered_comments. I'll make a PR with a test and a fix.

aurora-a-k-a-lightning commented 5 years ago

@Dantemss wow! Thank you for the quick reply and quick fix!! I really appreciate it :smile:

Dantemss commented 5 years ago

OK I released version 6.0.0 which should fix this issue. Please let me know if you run into any other issues.