Are relations from drizzle-orm actually needed? Need clarification on that #2649
Closed
zeuscronos
started this conversation in
General
Replies: 1 comment
-
You don't need to define relations unless you are going to include relations in queries. const posts = await db.query.posts.findMany({
// posts / comments relation has to be defined
with: { comments: true },
}); If you are only going to use |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have this dummy project: drizzle-question-relations.zip which contains these files:
/src/db/schema.ts
The content of that file is taken from: https://orm.drizzle.team/docs/rqb#many-to-many
I’m trying to understand the necessity of defining these specific relations in the ORM schema:
While I acknowledge that there are likely significant reasons for including these relational definitions in the ORM schema, I'm still exploring the tangible benefits they offer. Specifically, I'm interested in understanding the additional capabilities and functionalities that these relations enable, maybe the ability to perform specific types of queries or benefiting from enhanced code completion (IntelliSense), etc, etc.
From my initial experiments, I haven't observed any differences between the version of the code with these relations defined and the version without them.
I'm particularly curious if these relations facilitate certain operations that I might not have tested yet. Otherwise I prefer to use the simplest code version.
Here I have a test file:
/src/__tests__/user.test.ts
You can setup the code above and run it by doing the following (this requires a docker engine):
drizzle-question-relations
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions