diff --git a/pkg/models/task_search.go b/pkg/models/task_search.go index 0425cbf5e..190fd150d 100644 --- a/pkg/models/task_search.go +++ b/pkg/models/task_search.go @@ -261,8 +261,13 @@ func (d *dbTaskSearcher) Search(opts *taskSearchOptions) (tasks []*Task, totalCo limit, start := getLimitFromPageIndex(opts.page, opts.perPage) cond := builder.And(builder.Or(projectIDCond, favoritesCond), where, filterCond) + var distinct = "tasks.*" + if strings.Contains(orderby, "task_positions.") { + distinct += ", task_positions.position" + } + query := d.s. - Distinct("tasks.*"). + Distinct(distinct). Where(cond) if limit > 0 { query = query.Limit(limit, start)