Conditional Relational Queries
I have these tables Simplified Version
Is it possible to setup the table relationships so that depending on the ingredient type it utilizes the corresponding tables?
For example, with an ingredient type of ITEM it would use the item table instead of the food table.
3 Replies
I believe this is an open feature request:
https://github.com/drizzle-team/drizzle-orm/issues/1051
https://github.com/drizzle-team/drizzle-orm/issues/207
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...
Interesting, in that case for now I will just use the old querying method until there is a solution for it ![apuThumbsUp](https://cdn.discordapp.com/emojis/776688830781980704.png)
![apuThumbsUp](https://cdn.discordapp.com/emojis/776688830781980704.png)
One interesting way to do this differently that I just saw is by introducing an intermediate table. For simplicity I’ll use the example of comments on table a or table b. You can create a “comment set” table which rows on a and b point to, and then comments point to the comment set
I’m surprised I haven’t seen that recommended more honestly
It’s a similar mechanism as in a many:many relationship
I guess with a many:many relationship, you'd need an extra table since a tagset would be correlated to one row