How to create this kind of relation
I have a
prices
table which stores a price object, with some info such as currency_symbol
, currency_amount
and some more. The thing is this price should strictly have a one-to-one relationship with whatever is priced. For example in my taxes table the tax
should have a relationship with price
and in my products table the product
should have a relationship with price
and so on...
My current solution would be to create a few helper tables like tax_price
and have it store a price and be in relationship with tax
and the same for product. Is this necessary or is there a better way to implement something like this?2 Replies
If a given product can only have one price and this price can only have one tax and both price and tax are coupled (a given tax can only have a given price and vice versa) then you can design a table with 4 cols: id (primary key), productId, priceId, taxId (named productPrice ?)
With unique constraints on them.