join method
Creates a select statement that operates on more than one table by applying the given joins.
Example from the todolist example which will load the category for each item:
final results = await select(todos).join([
leftOuterJoin(categories, categories.id.equalsExp(todos.category))
]).get();
return results.map((row) {
final entry = row.readTable(todos);
final category = row.readTable(categories);
return EntryWithCategory(entry, category);
}).toList();
See also:
- https://drift.simonbinder.eu/docs/advanced-features/joins/#joins
- innerJoin, leftOuterJoin and crossJoin, which can be used to construct a Join.
- DatabaseConnectionUser.alias, which can be used to build statements that refer to the same table multiple times.
Implementation
JoinedSelectStatement join(List<Join> joins) {
final statement = JoinedSelectStatement(database, table, joins, distinct);
if (whereExpr != null) {
statement.where(whereExpr!.predicate);
}
if (orderByExpr != null) {
statement.orderBy(orderByExpr!.terms);
}
if (limitExpr != null) {
statement.limitExpr = limitExpr;
}
return statement;
}