From a4dbd43cfba6eaa56d5077e936e178767c6ed9c7 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Thu, 6 Feb 2020 01:45:21 +0100 Subject: [PATCH] Fix get comments by target --- .../sql/functions/comment/find_comments_by_target.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/sql/functions/comment/find_comments_by_target.sql b/src/main/resources/sql/functions/comment/find_comments_by_target.sql index b4ede4a..e8b5879 100644 --- a/src/main/resources/sql/functions/comment/find_comments_by_target.sql +++ b/src/main/resources/sql/functions/comment/find_comments_by_target.sql @@ -8,7 +8,7 @@ create or replace function find_comments_by_target( ) language plpgsql as $$ begin - select json_agg(t), (select count(id) from "comment" c3 where c3.target_id = _target_id) + select json_agg(t), (select count(id) from "comment" c3 where c3.parent_id = _target_id) into resource, total from ( select @@ -18,7 +18,7 @@ begin find_citizen_by_id(com.created_by_id) as created_by, count_vote(com.id) as votes from "comment" as com - where com.target_id = _target_id + where com.parent_id = _target_id order by case sort when 'votes' then (count_vote(com.id)->>'percent')::int