Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: polymorphic relationships #1

Open
carlos3g opened this issue Aug 27, 2024 · 1 comment
Open

feature: polymorphic relationships #1

carlos3g opened this issue Aug 27, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@carlos3g
Copy link
Owner

@carlos3g carlos3g added the enhancement New feature or request label Aug 27, 2024
@carlos3g carlos3g self-assigned this Aug 27, 2024
@carlos3g
Copy link
Owner Author

carlos3g commented Aug 27, 2024

This solution doesn't work as explained here.

Models tested:

model Quote {
  id                BigInt              @id @default(autoincrement()) @db.BigInt
  userOnFavoritable UserOnFavoritable[] @relation("UserOnQuote")

  @@map("quotes")
}

model Author {
  id                BigInt              @id @default(autoincrement()) @db.BigInt
  userOnFavoritable UserOnFavoritable[] @relation("UserOnAuthor")

  @@map("authors")
}

model UserOnFavoritable {
  user            User            @relation(fields: [userId], references: [id])
  userId          BigInt          @db.BigInt
  author          Author?         @relation("UserOnAuthor", fields: [favoritableId], references: [id], map: "author_favoritableId")
  quote           Quote?          @relation("UserOnQuote", fields: [favoritableId], references: [id], map: "quote_favoritableId")
  favoritableId   BigInt          @map("favoritable_id") @db.BigInt
  favoritableType FavoritableType @map("favoritable_type")

  @@unique([userId, favoritableId, favoritableType])
  @@map("user_on_favoritable")
}

Error:

Foreign key constraint failed on the field: `author_favoritableId (index)`
[...]
{
  code: 'P2003',
  clientVersion: '5.18.0',
  meta: { modelName: 'Quote', field_name: 'author_favoritableId (index)' }
}

carlos3g added a commit that referenced this issue Aug 27, 2024
carlos3g added a commit that referenced this issue Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant