Fix includeJoinedTableColumns and add test

This commit is contained in:
westito 2021-12-02 09:04:17 +01:00
parent f383eef2ee
commit ffe24bb17a
2 changed files with 38 additions and 2 deletions

View File

@ -43,8 +43,7 @@ class Join<T extends HasResultSet, D> extends Component {
/// Constructs a [Join] by providing the relevant fields. [on] is optional for
/// [_JoinType.cross].
Join._(this.type, this.table, this.on, {bool? includeInResult})
: includeInResult = includeInResult ?? true {
Join._(this.type, this.table, this.on, {this.includeInResult}) {
if (table is! ResultSetImplementation<T, D>) {
throw ArgumentError(
'Invalid table parameter. You must provide the table reference from '

View File

@ -401,6 +401,43 @@ void main() {
expect(result.read(todos.id.count()), equals(10));
});
test('use selectOnly(includeJoinedTableColumns) instead of useColumns',
() async {
final categories = db.categories;
final todos = db.todosTable;
final query =
db.selectOnly(categories, includeJoinedTableColumns: false).join([
innerJoin(
todos,
todos.category.equalsExp(categories.id),
)
]);
query
..addColumns([categories.id, todos.id.count()])
..groupBy([categories.id]);
when(executor.runSelect(any, any)).thenAnswer((_) async {
return [
{
'categories.id': 2,
'c1': 10,
}
];
});
final result = await query.getSingle();
verify(executor.runSelect(
'SELECT categories.id AS "categories.id", COUNT(todos.id) AS "c1" '
'FROM categories INNER JOIN todos ON todos.category = categories.id '
'GROUP BY categories.id;',
[]));
expect(result.read(categories.id), equals(2));
expect(result.read(todos.id.count()), equals(10));
});
test('injects custom error message when a table is used multiple times',
() async {
when(executor.runSelect(any, any)).thenAnswer((_) => Future.error('nah'));