$composableBuilder<T, C extends GeneratedColumn<Object> > method
T
$composableBuilder<T, C extends GeneratedColumn<Object> >({
- required C column,
- required T builder(
- C column
inherited
A helper method for creating composables that need the correct aliases for the column and the join builders. Every filter and ordering compasable is created using this method.
Explaination:
db.managers.categories.filter((f) => f.todos((todoFilterComposer) => todoFilterComposer.title.equals("Math Homework")))
In the above example, todoFilterComposer.title.equals("Math Homework")
creates a filter for the joined todos
table.
However this todoFilterComposer
class needs to create the filter using the alias name of the table,
This $composableBuilder
function utility helps us create it correctly
This function removes also joins when the arent needed
See $removeJoinBuilderFromRootComposer
for more information
Implementation
T $composableBuilder<T, C extends GeneratedColumn>(
{required C column, required T Function(C column) builder}) {
// The proper join builders and column for the builder
final C columnForBuilder;
// Get a copy of the column with the correct alias
final aliasedColumn = _aliasedColumn(column);
// If the column that the action is being performed on
// is part of the actual join, then this join is not needed.
// The action will then be performed on the original column.
if ($joinBuilder?.referencedColumn == aliasedColumn &&
$joinBuilder?.currentColumn is C) {
columnForBuilder = $joinBuilder?.currentColumn as C;
$removeJoinBuilderFromRootComposer($joinBuilder!);
} else {
columnForBuilder = aliasedColumn;
}
return builder(columnForBuilder);
}