Merge pull request #47 from debuggerx-dev/master
fix wrong sql generated when using multi 'orderBy'
This commit is contained in:
commit
1c1a9de7f5
2 changed files with 11 additions and 3 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((order) => order.compile()).join(', ');
|
||||||
b.write(' ORDER BY ${item.compile()}');
|
if (orderByClause.isNotEmpty) {
|
||||||
|
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');
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:angel3_orm/angel3_orm.dart';
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
@ -80,4 +79,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.id, descending: true);
|
||||||
|
query.orderBy(PersonOrderFields.personId, descending: true);
|
||||||
|
var orders = await query.get(executor);
|
||||||
|
expect(orders.first.idAsInt > orders.last.idAsInt, true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue