mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
fix: list order by not effective
This commit is contained in:
@@ -609,11 +609,22 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok
|
||||
}
|
||||
q, err = OrderByExtraFields(manager, ctx, q, userCred, orderQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "OrderByExtraFields")
|
||||
}
|
||||
if orderBy == nil {
|
||||
orderBy = []string{}
|
||||
}
|
||||
if primaryCol != nil && primaryCol.IsNumeric() {
|
||||
orderBy = append(orderBy, primaryCol.Name())
|
||||
} else if manager.TableSpec().ColumnSpec("created_at") != nil {
|
||||
orderBy = append(orderBy, "created_at")
|
||||
if manager.TableSpec().ColumnSpec("name") != nil {
|
||||
orderBy = append(orderBy, "name")
|
||||
}
|
||||
if primaryCol != nil {
|
||||
orderBy = append(orderBy, primaryCol.Name())
|
||||
}
|
||||
}
|
||||
for _, orderByField := range orderBy {
|
||||
if pagingConf != nil && utils.IsInStringArray(orderByField, pagingConf.MarkerFields) {
|
||||
// skip markerField in pagingConf
|
||||
@@ -628,17 +639,6 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok
|
||||
}
|
||||
}
|
||||
}
|
||||
if primaryCol != nil && primaryCol.IsNumeric() {
|
||||
orderBy = append(orderBy, primaryCol.Name())
|
||||
} else if manager.TableSpec().ColumnSpec("created_at") != nil {
|
||||
orderBy = append(orderBy, "created_at")
|
||||
if manager.TableSpec().ColumnSpec("name") != nil {
|
||||
orderBy = append(orderBy, "name")
|
||||
}
|
||||
if primaryCol != nil {
|
||||
orderBy = append(orderBy, primaryCol.Name())
|
||||
}
|
||||
}
|
||||
|
||||
if pagingConf != nil {
|
||||
q = q.Limit(int(limit) + 1)
|
||||
|
||||
Reference in New Issue
Block a user