Select item collection together with item count
Heads-up: I'm an SQL & Drizzle newbie
I have 3 tables:
users
, flashcard_collection
and flashcards
flashcard_collection
has a creatorId
foreign key which indicates what user a collection belongs to
flashcards
has a collectionId
foreign key which indicates what collection a flashcard belongs to
I want to select all flashcard collections that belong to a user together with each collection's flashcard count4 Replies
What do you have so far?
This works but doesn't return me the count
I've seen that queries like this don't work with aggregate functions and count is of such type
so I'm trying to do something in this style
The relational query builder does not support aggregations yet. You can either user the Crud API or the following workaround:
And then just count the array length with JS:
Oh my god why haven't I noticed that the
with
keyword works like that
Thank you
this solves my problem
wait
userCollections.flashcards
is an empty array
it shouldn't be
Ok I had a bad id in my relations