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