fix: list order by not effective

This commit is contained in:
Qiu Jian
2020-03-18 11:21:44 +08:00
parent 98af93bea3
commit 300f399f43
+12 -12
View File
@@ -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)