From 8558c5041f6279338a8a0cfe0b0235107db04879 Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Thu, 13 Dec 2018 16:16:12 +0100 Subject: [PATCH 1/2] fix active record induced error on postgres by removing distinct. Inlining the code did not turn out well, as we have to cope with the polymorphic association of user here.. --- app/models/request_for_comment.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/request_for_comment.rb b/app/models/request_for_comment.rb index fe15409b..2461ca7b 100644 --- a/app/models/request_for_comment.rb +++ b/app/models/request_for_comment.rb @@ -47,10 +47,10 @@ class RequestForComment < ApplicationRecord def commenters commenters = [] - comments.distinct.to_a.each {|comment| + comments.each {|comment| commenters.append comment.user } - commenters.uniq {|user| user.id} + commenters.uniq end def self.with_last_activity From 76079bb47d6c8618531bc702e9d6f649097ce69a Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Fri, 14 Dec 2018 13:36:24 +0100 Subject: [PATCH 2/2] one line the loop, thanks for the hint @MrSerth --- app/models/request_for_comment.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/models/request_for_comment.rb b/app/models/request_for_comment.rb index 2461ca7b..b4fa819b 100644 --- a/app/models/request_for_comment.rb +++ b/app/models/request_for_comment.rb @@ -46,11 +46,7 @@ class RequestForComment < ApplicationRecord end def commenters - commenters = [] - comments.each {|comment| - commenters.append comment.user - } - commenters.uniq + comments.map(&:user).uniq end def self.with_last_activity