HasMany, BelongsTo for price comparision problem

大憨熊 提交于 2019-12-25 15:54:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!