feat: check that table isn't joined twice

This commit is contained in:
2025-03-16 09:51:54 +07:00
parent 53872ea789
commit 21f0c44e41
2 changed files with 5 additions and 23 deletions

View File

@@ -9,6 +9,7 @@ import (
"golang.org/x/text/message"
"gorm.io/gorm/clause"
"reflect"
"slices"
"strings"
)
@@ -104,7 +105,9 @@ func SortByOrder[T any](fieldsSortingOrder []SortField, entity T) ([]*T, error)
joinField := strings.Join(joinPathParts, ".")
joinTable := field.Type.Name()
joins = append(joins, joinTable)
if !slices.Contains(joins, joinTable) {
joins = append(joins, joinTable)
}
orderQuery = append(orderQuery, fmt.Sprintf("%s %s", joinField, item.Order))
}
}