我想在我的网站上制作价格比较部分。现在我真的很难理解一个产品,一个商店和一个价格之间的关系。
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.
所以我有一个表产品,表商店和表价格,价格我存储product_id,shop_id和价格
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?
推荐答案我会这样定义:
Product hasAndBelongsToMany Shop with Price Shop hasAndBelongsToMany Product with Price在声明HABTM关系时,请检查 with 属性。您的建模是确定
check the "with" attribute when declaring a HABTM relation. Your modeling is ok
干杯
更多推荐
HasMany,BelongsTo的价格比较问题
发布评论