问题描述
在我的情况下,我有一个部分(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.
这篇关于什么是亲子关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!