HasMany,BelongsTo的价格比较问题 [英] HasMany, BelongsTo for price comparision problem

查看:185
本文介绍了HasMany,BelongsTo的价格比较问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上制作价格比较部分。现在我真的很难理解一个产品,一个商店和一个价格之间的关系。

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的价格比较问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆