I’m confused about what the behavior of a polymorphic relation would be.
My question is if we add a column invoiceId on table InvoicePaymentMapping
, which relates to two tables sales_invoice
and purchase_invoice
, and try to find a row with invoiceId 3.
Assume we have a row with id 3 in both the tables sales_invoice
and purchase_invoice
. What will happen?
What is the proper way to do this if it is not the right way?
My sample schema looks like this.
model InvoicePaymentMapping {
id Int @id @default(autoincrement())
invoiceId Int @map("invoice_id")
purchaseInvoice PurchaseInvoice? @relation(name:"invoice_payment_mapping_purchase_invoice_mapping", fields: [invoiceId], references: [id], onDelete: Restrict, onUpdate: Cascade, map: "purchase_invoice_id")
salesInvoice SalesInvoice? @relation(name: "invoice_payment_mapping_sales_invoice_mapping", fields: [invoiceId], references: [id], onDelete: Restrict, onUpdate: Cascade, map: "sales_invoice_id")
}