Directly accessing array of many to many relationship properties through junction table
I've set up a many-to-many relationship between one or more vocabulary items on one or more cards, but I can't quite seem to figure out how to set up the relations to go through the junction table but not have it appear nested in the results.
Here's the (simplified) schema:
Should this be possible in Drizzle? I'm on drizzle-orm 0.39.3 and using local dev Turso with @libsql/client.
5 Replies
I can run
db.query.cardsTable.findMany({ with: { vocabulary: { with: { vocabulary } })
and in the resulting rows vocabulary.vocabulary
has an array of he actual vocabulary fields, but I'd prefer it just be a single vocabulary
entry with the actual array.
If I just run db.query.cardsTable.findMany({ with: { vocabulary: true })
, then vocabulary
is an array of cardId
and vocabularyId
.Looks like this is discussed here as a new feature, so for now, I would have to do a wrapper an remove the nesting myself:
https://github.com/drizzle-team/drizzle-orm/issues/2933
GitHub
[FEATURE]: API for to 'flatten' response shapes when querying data ...
Describe what you want Overview / Explanation Default aggregation behaviour of Drizzle Queries is to provide nested response objects with the table name of the relation as the key, and an object of...
So basically
So then each row looks like this:
Well, answering more of my own question, looks like
through
is coming in the Relational API v2
https://github.com/drizzle-team/drizzle-orm/discussions/2316GitHub
Relational API v2 · drizzle-team drizzle-orm · Discussion #2316
We've launched Drizzle Relational Queries exactly a year ago and it's time to ship a fundamental upgrade. We've gathered a massive amount of valuable feedback from the community and goi...
Thank you for coming to my TED talk