diff --git a/packages/orm/angel_orm/lib/src/query.dart b/packages/orm/angel_orm/lib/src/query.dart index 91f6980f..1e4f6e81 100644 --- a/packages/orm/angel_orm/lib/src/query.dart +++ b/packages/orm/angel_orm/lib/src/query.dart @@ -331,8 +331,9 @@ abstract class Query extends QueryBase { 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((order) => order.compile()).join(', '); + if (orderByClause.isNotEmpty) { + b.write(' ORDER BY $orderByClause'); } if (_limit != null) b.write(' LIMIT $_limit'); if (_offset != null) b.write(' OFFSET $_offset'); diff --git a/packages/orm/angel_orm_test/lib/src/join_test.dart b/packages/orm/angel_orm_test/lib/src/join_test.dart index b380de64..efe4c969 100644 --- a/packages/orm/angel_orm_test/lib/src/join_test.dart +++ b/packages/orm/angel_orm_test/lib/src/join_test.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:math'; import 'package:angel3_orm/angel3_orm.dart'; import 'package:test/test.dart'; @@ -80,4 +79,12 @@ void joinTests(FutureOr Function() createExecutor, element.personAge == originalPerson?.age), true); }); + + test('select orders with multi order by fields', () async { + var query = PersonOrderQuery(); + query.orderBy(PersonOrderFields.id, descending: true); + query.orderBy(PersonOrderFields.personId, descending: true); + var orders = await query.get(executor); + expect(orders.first.idAsInt > orders.last.idAsInt, true); + }); }