Join statement just ignored in Dart API #2668
-
Hi there, when trying to compose a query using Dart API, I am facing a wierd problem. Everything works well except join statement - highlighted in code below: final tasksQuery = database.select(database.tasks);
// WHERE CONDITIONS - OK
tasksQuery.where((t) => t.deletedAt.isNull());
if (hideDoneTasks) {
tasksQuery.where((t) => t.status.equals(0));
}
if (showOnlyImportantTasks) {
tasksQuery.where((t) => t.important.equals(1));
}
// -------------------- ABSOLUTELY IGNORED ---------------------
tasksQuery.join([
innerJoin(database.peopleTasks, database.peopleTasks.taskId.equalsExp(database.tasks.id)),
]).where(
database.peopleTasks.personId.equals(personId),
);
// -------------------- END OF ABSOLUTELY IGNORED ---------------------
// LIMIT - OK
tasksQuery.limit(tasksLimit);
// GET TASKS
final tasks = await tasksQuery.get(); The previous code generates query like this: When i write pure sql query, there is no problem with joining. I have also triple checked the table definition, but I dont see a problem here neither. @DataClassName('PersonTask')
class PeopleTasks extends Table {
IntColumn get id => integer().autoIncrement()();
IntColumn get personId => integer().references(People, #id, onDelete: KeyAction.cascade)();
IntColumn get taskId => integer().references(Tasks, #id, onDelete: KeyAction.cascade)();
} I am probably missing something important, but after two days of digging to nowhere, I have no idea what to do except of conversion to sql. Any hint would be highly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Unlike methods like So you can fix the snippet by storing the result of final joined = tasksQuery.join([
innerJoin(database.peopleTasks, database.peopleTasks.taskId.equalsExp(database.tasks.id)),
]).where(
database.peopleTasks.personId.equals(personId),
);
joined.limit(tasksLimit);
final rows = await joined.get(); For each row in |
Beta Was this translation helpful? Give feedback.
Unlike methods like
where
that mutate the single-table query,join
returns a new object. This is required because we can't have callback-like APIs forWHERE
s on joins, so the interface of the statement is slightly different after adding the join.So you can fix the snippet by storing the result of
join
in a new variable:For each row in
rows
, you can get the todo item withreadTable(database.tasks)
and the associate…