Hey all, huge fan of Prisma! Thanks for creating s...
# orm-help
r
Hey all, huge fan of Prisma! Thanks for creating such an awesome product! Been building a product called Debatable, and trying to extend the schema to have multiple Poll fields in a single debate. Is this possible? Thanks in advance for any help!
Copy code
model Debate {
  id        Int          @id @default(autoincrement())
  topic     String
  status    DebateStatus @default(UPCOMING)
  createdAt DateTime     @default(now())
  isDaily   Boolean      @default(false)
  start     DateTime?
  end       DateTime?
  author    User         @relation("UserAuthorsDebate", fields: [authorId], references: [id])
  authorId  Int
  posts     Post[]
  upvotedBy User[]       @relation("UserUpvotesDebate", references: [id])
  poll      Poll?
  revisedPoll Poll?     <------------------------------- Want to add this! 
}

model Poll {
  id       Int          @id @default(autoincrement())
  debate   Debate       @relation(fields: [debateId], references: [id])
  debateId Int          @unique
  options  PollOption[]
}
1
a
Hey Robert! This is definitely possible, in fact it will use the same pattern as
author
and
upvotedBy
fields. You need to disambiguate the relations by using the
@relation
attribute and passing a unique name. Let me know if you run into any trouble!
r
hey @Austin, thanks so much for the response here! whenever I try to use the same approach the formatter changes it to this:
Copy code
model Debate {
  id          Int          @id @default(autoincrement())
  topic       String
  status      DebateStatus @default(UPCOMING)
  createdAt   DateTime     @default(now())
  isDaily     Boolean      @default(false)
  start       DateTime?
  end         DateTime?
  author      User         @relation("UserAuthorsDebate", fields: [authorId], references: [id])
  authorId    Int
  upvotedBy   User[]       @relation("UserUpvotesDebate", references: [id])
  poll        Poll?        @relation("pollForDebate", fields: [pollId], references: [id])
  revisedPoll Poll?        @relation("revisedPollForDebate", fields: [pollId], references: [id])
  posts       Post[]
  Poll        Poll[]
  pollId      Int?
  pollId      Int?
}

model Poll {
  id       Int          @id @default(autoincrement())
  debate   Debate       @relation(fields: [debateId], references: [id])
  debateId Int          @unique
  options  PollOption[]
  Debate   Debate[]
  Debate   Debate[]
}
any ideas for what I’m doing wrong?
for context I’m trying to add the last field
Copy code
model Debate {
  id        Int          @id @default(autoincrement())
  topic     String
  status    DebateStatus @default(UPCOMING)
  createdAt DateTime     @default(now())
  isDaily   Boolean      @default(false)
  start     DateTime?
  end       DateTime?
  author    User         @relation("UserAuthorsDebate", fields: [authorId], references: [id])
  authorId  Int
  upvotedBy User[]       @relation("UserUpvotesDebate", references: [id])
  posts     Post[]
  poll      Poll? @relation("pollForDebate")
  revisedPoll Poll? @relation("revisedPollForDebate")
}
thinking of just creating a duplicate of the Poll model called
RevisedPoll
but seems a little messy 😅
a
Ok, I think this should work for you:
Copy code
model Debate {
  id            Int       @id @default(autoincrement())
  topic         String
  createdAt     DateTime  @default(now())
  isDaily       Boolean   @default(false)
  start         DateTime?
  end           DateTime?
  authorId      Int
  poll          Poll?     @relation(name: "poll", fields: [pollId], references: [id])
  pollId        Int?      @unique
  revisedPoll   Poll?     @relation(name: "revised_poll", fields: [revisedPollId], references: [id])
  revisedPollId Int?      @unique
}

model Poll {
  id              Int     @id @default(autoincrement())
  debateId        Int?    @unique
  debate          Debate? @relation(name: "poll")
  revisedDebateId Int?    @unique
  revisedDebate   Debate? @relation(name: "revised_poll")
r
amazing, thanks so much for this!