From 5b70609ba760ea68b43f6d42a69a1b32eeb2abec Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 28 Feb 2024 14:35:09 +0100 Subject: [PATCH] fix: usage of limit and order by usage in recursive cte --- pkg/models/project.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pkg/models/project.go b/pkg/models/project.go index 4962624d3c..574c814f11 100644 --- a/pkg/models/project.go +++ b/pkg/models/project.go @@ -443,12 +443,8 @@ SELECT p.* FROM projects p INNER JOIN all_projects ap ON p.parent_project_id = ap.id` currentProjects := []*Project{} - err = s.SQL(`WITH RECURSIVE all_projects as ( -`+baseQuery+` -ORDER BY position -`+limitSQL+` -) -SELECT * FROM all_projects GROUP BY all_projects.id ORDER BY position`, args...).Find(¤tProjects) + err = s.SQL(`WITH RECURSIVE all_projects as (`+baseQuery+`) +SELECT DISTINCT * FROM all_projects ORDER BY position `+limitSQL, args...).Find(¤tProjects) if err != nil { return } @@ -459,7 +455,7 @@ SELECT * FROM all_projects GROUP BY all_projects.id ORDER BY position`, args...) totalCount, err = s. SQL(`WITH RECURSIVE all_projects as (`+baseQuery+`) -SELECT count(*) FROM all_projects`, args...). +SELECT count(*) FROM all_projects GROUP BY all_projects.id`, args...). Count(&Project{}) if err != nil { return nil, 0, err