mirror of https://github.com/AMT-Cheif/drift.git
Fix includeJoinedTableColumns and add test
This commit is contained in:
parent
f383eef2ee
commit
ffe24bb17a
|
@ -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 '
|
||||
|
|
|
@ -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'));
|
||||
|
|
Loading…
Reference in New Issue