Nathaniel Babalola
01/27/2022, 8:50 PMUser
table and a Transactions
table for storing transactions between users.
The Transactions
table has a from and to field , which should reference the id of the users sending and receiving on User
table.
How can 2 fields/columns reference the same key on another table.
I can't do any of these.
user user @relation(fields: [from, to], references :[id] )
user user @relation(fields: [from, to], references :[id, id] )
Please any help is greatly appreciated.Nurul
01/28/2022, 5:03 AMmodel User {
id Int @id @default(autoincrement())
name String @unique
email String @unique
Sender Transaction[] @relation("sender")
Receiver Transaction[] @relation("receiver")
}
model Transaction {
id Int @id @default(autoincrement())
from User @relation("sender", fields: [senderId], references: [id])
senderId Int @unique
to User @relation("receiver", fields: [receiverId], references: [id])
receiverId Int @unique
}
Nathaniel Babalola
01/28/2022, 10:28 AM