t3-oss / create-t3-app

The best way to start a full-stack, typesafe Next.js app
https://create.t3.gg
MIT License
24.09k stars 1.1k forks source link

drizzle relation is not a Foreign key #1583

Open nagy-nabil opened 9 months ago

nagy-nabil commented 9 months ago

Is your feature request related to a problem? Please describe.

it's more of a suggestion than a problem, from drizzle docs #foreign-keys

While foreign keys serve a similar purpose - defining relations between tables, they work on a different level compared to relations. Foreign keys are a database level constraint, they are checked on every insert/update/delete operation and throw an error if a constraint is violated. On the other hand, relations are a higher level abstraction, they are used to define relations between tables on the application level only. They do not affect the database schema in any way and do not create foreign keys implicitly. What this means is relations and foreign keys can be used together, but they are not dependent on each other. You can define relations without using foreign keys (and vice versa), which allows them to be used with databases that do not support foreign keys, like PlanetScale.

t3 uses PlanetScale driver so no foreign keys are available, but for someone new to drizzle leaving a comment stating that fact would be better DX

Describe the solution you'd like to see

leave a comment with the foreign keys docs lettings the user know if they change planetScale and need foreign keys on the database level they need to do more work

Describe alternate solutions

idk

Additional information

No response

barrybtw commented 6 months ago

Foreign keys are now a beta feature of PlanetScale.