I have a situation that I can only describe by example. I tend to think this must be a common problem in a relational model. This problem exists in a pretty critical area of my application, so I want to make sure I make the right decision.
Imagine a basic order application for a company that sells both products and services. Products and services need to be stored in different tables, because they each have their own attributes, and they each relate to different tables. But they both need (?) to be referenced in the OrderLines table.
Customer
CustomerId
Order
OrderId
CustomerId
Product
ProductId
ProductTypeId
etc
Service
ServiceId
ServiceTypeId
etc
Now each order will need to have one or many OrderLine records. Each orderline row can either be a service OR a product.
I hate this practice:
OrderLine
OrderLineId
ProductOrServiceId (or "ObjectId")
I'm also not a fan of:
OrderLine
OrderLineId
ProductId (nullable)
ServiceId (nullable)
(one or the other must be null, and one must be non-null)
I could do this:
OrderLine
OrderLineId
OrderLineTypeId
OrderLineType
OrderLineTypeId
Service
ServiceId
OrderLineTypeId
Product
ProductId
OrderLineTypeId
This would allow me to tie everything together, but I think it just moves the problem of a relationship going in or direction or another to the OrderLineType table.
Again, this must be a relatively common problem. Any opinions on how to handle this sort of thing?