什么是亲子关系? [英] What are Parent-Child relationships?

查看:130
本文介绍了什么是亲子关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的情况下,我有一个部分(Say螺丝)和产品资料。为了论证,产品材料(如钢铁)只能属于一个部分(但不在现实世界中)。所以这是1:n。该部分将在ProductMaterial表中将其作为fk的pk。



在这种情况下,哪个是父母,哪个是小孩?

解决方案

您可以通过这种方式解释数据库中的1:n关系:一个小孩永远是保存外键的模型,因为这表示它所属的位置。

当然,如果你有自己的引用模型/表,你必须用不同的方式来看它。


What is the parent and what is the child in a sql relationship?

In my case, I have a part (Say screw), and product material. For argument's sake, a product material (eg steel) can only belong to one part (but not in the real world). So this is 1:n. The part will have its pk as a fk in the ProductMaterial table.

Which is parent and which is child in this case?

解决方案

You can interpret a 1:n relationship in database this way: A child is always that model which holds the foreign key as this indicates where it belongs to.
Of course if you have self referencing models/tables you have to look at it in a different way.

这篇关于什么是亲子关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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