Merge pull request #47 from debuggerx-dev/master

fix wrong sql generated when using multi 'orderBy'
This commit is contained in:
Thomas Hii 2022-01-12 18:45:02 +08:00 committed by GitHub
commit 1c1a9de7f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 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((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');

View file

@ -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<QueryExecutor> 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);
});
}