Fix get comments by target

This commit is contained in:
2020-02-06 01:45:21 +01:00
parent eb7a0c7210
commit a4dbd43cfb

View File

@@ -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