mirror of https://github.com/AMT-Cheif/drift.git
Fixes join when adding columns to "regular" select
This commit is contained in:
parent
07d58eb058
commit
fb919eeedb
|
@ -95,7 +95,7 @@ class SimpleSelectStatement<T extends Table, D extends DataClass>
|
|||
|
||||
/// {@macro moor_select_addColumns}
|
||||
JoinedSelectStatement addColumns(List<Expression> expressions) {
|
||||
return join(const [])..addColumns(expressions);
|
||||
return join([])..addColumns(expressions);
|
||||
}
|
||||
|
||||
/// Orders the result by the given clauses. The clauses coming first in the
|
||||
|
|
|
@ -223,6 +223,48 @@ void main() {
|
|||
expect(result.read(descriptionLength), 11);
|
||||
});
|
||||
|
||||
test('supports custom columns + join', () async {
|
||||
final todos = db.alias(db.todosTable, 't');
|
||||
final categories = db.alias(db.categories, 'c');
|
||||
final descriptionLength = categories.description.length;
|
||||
|
||||
final query = db.select(categories).addColumns([descriptionLength]).join([
|
||||
innerJoin(
|
||||
todos,
|
||||
categories.id.equalsExp(todos.category),
|
||||
useColumns: false,
|
||||
)
|
||||
]);
|
||||
|
||||
when(executor.runSelect(any, any)).thenAnswer((_) async {
|
||||
return [
|
||||
{'c.id': 3, 'c.desc': 'Description', 'c.priority': 1, 'c3': 11}
|
||||
];
|
||||
});
|
||||
|
||||
final result = await query.getSingle();
|
||||
|
||||
verify(executor.runSelect(
|
||||
'SELECT c.id AS "c.id", c."desc" AS "c.desc", c.priority AS "c.priority"'
|
||||
', LENGTH(c."desc") AS "c3" '
|
||||
'FROM categories c '
|
||||
'INNER JOIN todos t ON c.id = t.category;',
|
||||
[],
|
||||
));
|
||||
|
||||
expect(
|
||||
result.readTable(categories),
|
||||
equals(
|
||||
Category(
|
||||
id: 3,
|
||||
description: 'Description',
|
||||
priority: CategoryPriority.medium,
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(result.read(descriptionLength), 11);
|
||||
});
|
||||
|
||||
test('group by', () async {
|
||||
final categories = db.alias(db.categories, 'c');
|
||||
final todos = db.alias(db.todosTable, 't');
|
||||
|
|
Loading…
Reference in New Issue