Is it possible to have conditional foreign key relation?
I want to set the foreign key conditionally based on the
bookingFor
field value. If bookingFor = 'MOVIE'
it should point to movie
table, similarly if the bookingFor = 'EVENT'
then it needs to point to event
table.1 Reply
No you can't conditionally set FK relation
What you're describing is Polymorphic Associations.
In native Postgres you'd have more flexible in how you could do this but for Drizzle specifically read the following issue:
https://github.com/drizzle-team/drizzle-orm/issues/1051
GitHub
[FEATURE]: Support Polymorphic Association · Issue #1051 · drizzle-...
Describe what you want I'm looking for a Typesafe ORM that support for polymorphic associations. To give a concrete example: I have a Comment model. I need this model to be associated with both...