fix_multi_order_by
This commit is contained in:
parent
9d161b91d4
commit
97855f4bf4
2 changed files with 11 additions and 2 deletions
|
@ -331,8 +331,9 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
|
||||||
b.write(' WHERE $whereClause');
|
b.write(' WHERE $whereClause');
|
||||||
}
|
}
|
||||||
if (_groupBy != null) b.write(' GROUP BY $_groupBy');
|
if (_groupBy != null) b.write(' GROUP BY $_groupBy');
|
||||||
for (var item in _orderBy) {
|
var orderByClause = _orderBy.map(item.compile()).join(', ');
|
||||||
b.write(' ORDER BY ${item.compile()}');
|
if (orderByClause?.isNotEmpty == true) {
|
||||||
|
b.write(' ORDER BY $orderByClause');
|
||||||
}
|
}
|
||||||
if (_limit != null) b.write(' LIMIT $_limit');
|
if (_limit != null) b.write(' LIMIT $_limit');
|
||||||
if (_offset != null) b.write(' OFFSET $_offset');
|
if (_offset != null) b.write(' OFFSET $_offset');
|
||||||
|
|
|
@ -80,4 +80,12 @@ void joinTests(FutureOr<QueryExecutor> Function() createExecutor,
|
||||||
element.personAge == originalPerson?.age),
|
element.personAge == originalPerson?.age),
|
||||||
true);
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue