I am revising a legacy multi-tenant application where the shopping cart function stores multiple vendors and multiple clients in the same database. Some clients of one vendor may be clients of a different vendor. Some vendors might actually be clients of another vendor.
I currently have a table for the super-type 'party' with primary key party_ID
, a table for the subtype 'company' with primary key company_ID
(references party_ID
) and a table for the role of 'vendor' with primary key vendor_ID
(references company_ID
). I also have a junction table, 'client' with a composite primary key of vendor_ID
and party_ID
.
My question is how should the 'order' table reference the vendor and client tables? My first thought is that the table should have a composite primary key of vendor_ID
, client_ID
and order_ID
(order_ID
could be auto-increment across the table or sequential per vendor_ID + client_ID
)
but this seemed a bit fishy as there were three attributes making up the key...
Does anyone have any insight into this topic? Most 'shopping carts' only deal with a single vendor, so the order table simply lists client_ID
as a foreign key.
Thanks!