hacktographer
DTDrizzle Team
•Created by hacktographer on 8/25/2023 in #help
How are you all seeding your database?
And I found this which clears up so many questions: https://discord.com/channels/1043890932593987624/1141321911155036232
11 replies
DTDrizzle Team
•Created by hacktographer on 8/25/2023 in #help
How are you all seeding your database?
Oh hey I found this on youtube which might get me like 90% of the way there: https://youtu.be/a1DPO7siG4s?t=1404
11 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
Dear Future Reader: Here is a stackoverflow answer that gives an example of how to achieve this pattern using only SQL: https://stackoverflow.com/a/2333543
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
yeah that's nice -- I'll try with this style. Thank you so much!
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
IMO it's not necessary that something like this is built-in to the tool, as long as the effect can be achieved.
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
Since this is such a common pattern, it might be worth adding to the official documentation.
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
ahh ok I see. This is clear enough, and solves the problem
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
I think it's a common pattern, and I'd like to have some nice syntax for it -- and before I start trying to implement something on my own I'd like to be sure that the feature doesn't already exist in Drizzle ORM.
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
right -- like this in rails: https://www.freecodecamp.org/news/polymorphic-association-ruby-on-rails/
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
for future reference, here's the github discussion about this topic for Prisma: https://github.com/prisma/prisma/issues/1644
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
It's ok to not have foreign keys, I'm just looking for some syntactical sugar so I can get a list of a user's memberships to different groups
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
Right - but it might be multiple tables. A "user" could have a "membership" to multiple types of "groups". Staff, Insured Members, Affiliate Marketers, Service Providers, etc.
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
Ah I just now saw this: https://github.com/drizzle-team/drizzle-orm/issues/207
29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
In this example, a
User
might have a membership in both the StaffGroups
and InsuredGroups
tables, and we use membershipsTable.contextType
to say one relationship is with StaffGroups
and the other is with InsuredGroups
. Two different rows in the same table, both with the same userId
but with the contextId
value referencing the id
field of either the staffGroupsTable
or insuredGroupsTable
. The documentation for Relational Queries appears to have the table hard-coded. Maybe I could make that dynamic instead somehow?29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
So with the polymorphic relationship, I have 2 columns which combine to create a relationship between different tables. In my case, I have
contextType
and contextId
- the contextType
would define a relationship between membershipsTable
and some other table, while contextType
would tell me which row from the table referenced by contextType
I should retrieve.29 replies
DTDrizzle Team
•Created by hacktographer on 8/22/2023 in #help
Polymorphic Associations?
Hello @Raphaël M (@rphlmr) ⚡ - thanks for the tip.
29 replies