bun
bun copied to clipboard
Override default polymorphic column value
I am trying to make my bun model based of an existing database schema. There is an existing table that has a column called TransType that contains the polymorphic key. When InventoryReceiptLine is using InvTran it is linked by an IRA key. The problem is when using buns polymorphic relations it expects the key to be InventoryReceiptsLine which it is not. Can I override what the string is stored in the polymorphic column?
InventoryReceiptLine
type InventoryReceiptLine struct {
bun.BaseModel `bun:"table:inventory_receipts_line"`
ReceiptNumber int32 `bun:"receipt_number,pk"`
InvMastUid int32 `bun:"inv_mast_uid"`
OrderTransactions []*InvTran `bun:"rel:has-many,join:inv_mast_uid=inv_mast_uid,join:type=trans_type,polymorphic"`
}
InvTran
type InvTran struct {
bun.BaseModel `bun:"table:inv_tran"`
TransactionNumber float32 `bun:"transaction_number,pk"`
InvMastUid int32 `bun:"inv_mast_uid"`
TransType string `bun:"trans_type"`
}
I would also very much like to be able to override the polymorphic type
name.
Maybe instead of type
, you could allow static values in JOIN, as in join:'my-type'=trans_type
?