Hi, wanna ask a question here. I have this schema ...
# orm-help
r
Hi, wanna ask a question here. I have this schema
Copy code
model User {
  walletAddress String   @id
  twitterHandle String?
  website       String?
  bio           String?
  username      String?
  signedAt      DateTime @default(now())
  logs          Log[]

  @@map("users")
}

model Log {
  id          Int      @id @default(autoincrement())
  from        User?    @relation("fromAddressRelation", fields: [fromAddress], references: [walletAddress])
  fromAddress String?
  to          User?    @relation("toAddressRelation", fields: [toAddress], references: [walletAddress])
  toAddress   String?
  createdAt   DateTime @default(now())

  @@map("logs")
}
The
from
and
to
property in the
Log
model gives me an error says that "Error validating field
from
in model `Log`: The relation field
from
on Model
Log
is missing an opposite relation field on the model
User
. Either run
prisma format
or add it manually". I want to
User
model only has one
Log
relation. How do I fix this? Thank you
n
Hey ๐Ÿ‘‹ This is what you need
Copy code
model User {
  walletAddress String   @id
  twitterHandle String?
  website       String?
  bio           String?
  username      String?
  signedAt      DateTime @default(now())
  fromLogs      Log[]    @relation("fromAddressRelation")
  toLogs        Log[]    @relation("toAddressRelation")


  @@map("users")
}

model Log {
  id          Int      @id @default(autoincrement())
  from        User?    @relation("fromAddressRelation", fields: [fromAddress], references: [walletAddress])
  fromAddress String?
  to          User?    @relation("toAddressRelation", fields: [toAddress], references: [walletAddress])
  toAddress   String?
  createdAt   DateTime @default(now())

  @@map("logs")
}
Prisma requires that every relation field must be on both sides of the model
r
I see. So I can't just have one relation field in
User
model?
n
You could have one relation field in User model but itโ€™s corresponding model should also have relation field. So for example if User has a relation field with Log model then Log should also have a relation field with User model.
๐Ÿ‘ 1