fix_multi_order_by

This commit is contained in:
debuggerx01 2022-01-11 17:46:56 +08:00
parent 9d161b91d4
commit 97855f4bf4
2 changed files with 11 additions and 2 deletions

View file

@ -331,8 +331,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
b.write(' WHERE $whereClause');
}
if (_groupBy != null) b.write(' GROUP BY $_groupBy');
for (var item in _orderBy) {
b.write(' ORDER BY ${item.compile()}');
var orderByClause = _orderBy.map(item.compile()).join(', ');
if (orderByClause?.isNotEmpty == true) {
b.write(' ORDER BY $orderByClause');
}
if (_limit != null) b.write(' LIMIT $_limit');
if (_offset != null) b.write(' OFFSET $_offset');

View file

@ -80,4 +80,12 @@ void joinTests(FutureOr<QueryExecutor> Function() createExecutor,
element.personAge == originalPerson?.age),
true);
});
test('select orders with multi order by fields', () async {
var query = PersonOrderQuery();
query.orderBy(PersonOrderFields.personId, descending: true);
query.orderBy(PersonOrderFields.id, descending: true);
var orders = await query.get(executor);
expect(orders.first.personId > orders.last.personId, true);
});
}