I was trying this for 5 hours and i could'n find an solution for this. I want an nested query, for an many to many relationship. If I go with my User, Books, userBooksLikes example again. (For better understanding: I want to track in the userBookLikes Table which user likes what books. It has two forgeign keys, the IDs from Books and Users. ) I want to query books, on which an Like does not exist. So I need an SQL Query like this:
SELECT * FROM Book WHERE id NOT IN (SELECT bookID from userBooksLikes WHERE userID = givenUserID)
Or something similar to it. The only possibility to do that, that I found in the Documentation was
final q = Query<Parent>(context)
..where((c) => c.children.haveAtLeastOneWhere.age).greaterThan(1);
..join(set: (p) => p.children);
final parentsWithOlderChildren = await q.fetch();
But this seems not to work. I made it now by deleting the data after the fetch, but i don't this this scales.
final bookQuery = Query<Book>(context);
userID = 1;
bookQuery
.join(set: (e) => e.usrBookLikes).returningProperties((ubl) => [ubl.user.id]);
final books = await BookQuery.fetch();
books.forEach((e) => e.usrBookLikes.removeWhere((e) => e.user.id != userId));
books.removeWhere((e) => e.usrBookLikes.isNotEmpty);
books.forEach((e) => e.removePropertiesFromBackingMap(["usrBookLikes"]));
return Response.ok(books);
Is there a way to do it with an database query?