lml/commontator

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

Closed this issue ยท 3 comments

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 ๐Ÿ˜„
Thank you!

Thanks for the bug report. Should be a simple fix: changing

ordered_comments(show_all).where(parent_id: all_parent_ids)
to use filtered_comments instead of ordered_comments. I'll make a PR with a test and a fix.

@Dantemss wow! Thank you for the quick reply and quick fix!!
I really appreciate it ๐Ÿ˜„

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