Difference between reference and relation?

Can someone help me to understand these? I'm trying to setup a new DB schema with a number one to one, one to many, and many to many relationships, and I'm a bit unsure about how to correctly link them, as well as setting up the many to many join tables using Drizzle. Should I be using both reference and relations? Any help would be greatly appreciated!
1 Reply
Mario564
Mario5644mo ago
Hi there. It seems you're new to using Drizzle. The references method in a column generates a database foreign key constraint while the relations function is an abstraction that Drizzle provides to be able to use its alternative query method RQB. If you're only going to be using select and not RQB, then there's no need to export relations, but if you're going to be using it, then you absolutely must export them. As for how to declare 1:1, 1:N and N:M relations, you can refer to the Drizzle documentation. For many-to-many, you want to declare a another table that links the other two tables (sometimes known as a "junction table"). Highly recommend reading the Drizzle documentation and the documentation for the database language and/or engine you're using.
Drizzle ORM - Select
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Drizzle ORM - Indexes & Constraints
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Want results from more Discord servers?
Add your server