best approach to load 2 tables that has no relationship but rather has a foreign key

i need to load user all user table with finyMany and also in the process attach all the wallet table balances for each user. The wallet table has a foreign key of user_id which is the id on the row on the User table
6 Replies
baotaoh
baotaoh3y ago
why do you not want to add relation? The objective of a fk is to link data https://www.prisma.io/docs/guides/general-guides/database-workflows/foreign-keys
Prisma
Foreign keys
Foreign keys
Lopen
LopenOP3y ago
So a relationship is not necessary to link 2 tables together? But in here they used relationship
baotaoh
baotaoh3y ago
On the db level it is. but you can also reference it programmatically. I.e find user -> find wallet with userid -> user & wallet. with relation you just include the related table in the same query. Yes that’s the correct way.
baotaoh
baotaoh3y ago
Prisma
Relations (Reference)
A relation is a connection between two models in the Prisma schema. This page explains how you can define 1-1, 1-n and m-n relations in Prisma.
Lopen
LopenOP3y ago
Okay thanks that was my confusion Because the original code base is laravel so I'm converting to typescript The funny thing no instance of relationship was mentioned there Only foreign key seems laravel does all this automatically I forget to check the user models turns out it has a relationship there
baotaoh
baotaoh3y ago
Oh i see, glad you figured it out. 💪
Want results from more Discord servers?
Add your server