问题
I want to make a price comparison section on my site. Now I really have trouble understanding the relationships between a Product, a Shop and a Price.
A Product is available in multiple Shops, who each have a Price.
So I have a table Products, a table Shops and a table Prices, in Prices I store the product_id, the shop_id and the price
Just to check, I would define it like this:
Product hasManyAndBelongsTo Shop
Shop hasManyAndBelongsTo Product
Price belongsTo Shop
Price belongsTo Product
But I feel this is not correct, is anyone able to give me the right connections?
回答1:
I'd define it like this:
Product hasAndBelongsToMany Shop with Price
Shop hasAndBelongsToMany Product with Price
check the "with" attribute when declaring a HABTM relation. Your modeling is ok
Cheers
来源:https://stackoverflow.com/questions/6815254/hasmany-belongsto-for-price-comparision-problem