试图避免循环引用

试图避免循环引用

本文介绍了试图避免循环引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置一个新的数据库,我正在浏览一个循环引用,我不确定最佳的设计方法。

I'm setting up a new database and I'm coming across a circular reference and I'm unsure of the best way to design this.

所以这里这是简单的英文。

so here it is in plain English.

我有一个食谱。配方要求配料。这一切都很好,除了食谱的一个成分可能需要另一个食谱,或者它可能是一个商店买的物品。

I have a recipe. the recipe calls for ingredients. this is all fine and good except one of the ingredients for the recipe might require another recipe or it might be a store bought item.

例如:
I想要做一个沙拉(食谱)_
它会有生菜,胡萝卜,洋葱(到目前为止都很好,只是存储买的成分)。
但我想要有牧场敷料。 (呃,我可以在商店购买牧场敷料,但是我有一个牧场敷料的食谱,我想用来做牧场敷料)。

for example:I want to make a salad (recipe)
It will have lettuce, carrots, onions (All good so far. just store bought ingredients.)
but I want to have ranch dressing. (uh oh, I can buy ranch dressing at the store but I have a recipe for ranch dressing that I want to use to make the ranch dressing.)

去最好的方式创建食谱和配料表?我有一个想法已经准备好了如何做,但它涉及循环引用,所有的网站说远离它。

how would you go about creating the recipe and ingredients tables in the best fashion? I have a thought all ready on how to do it but It involved circular referencing and all the web sites say stay away from it.

推荐答案

我会建议以下表格:

a)食谱 - 名称,描述,意见和其他信息

a) Recipe - name, description, isingredient and other information

b)成分 - 名称,描述,fromstore(如果从商店购买,是是或否值),recipieid的配方)。这使得成分能够获得配方

b) Ingredient - name, description, fromstore (yes or no value if its bought from a store), recipieid (the id of the recipe for this ingredient). This enables ingredients to have recipies

c)recipie_ingredients - receipieid,ingredientsid(基本上这与配方配合使用)

c) recipie_ingredients - receipieid, ingredientid (basically this ties a recipe to its ingredients)

建议是正确的,因为你最终可以以循环形式成分配方等等。

The advice is correct, since you can end up in a circular loop form ingredients to recipies etc

更新:我建议在食谱中添加一个isingridient列,以便只有已知是成分的配方才可以添加到成分表中。这可以帮助减少循环引用的机会

UPDATE: I would recommend adding an isingridient column to recipe so that only recipes which are known to be ingredients are selectable to add to the Ingredient table. This can help reduce the chances of circular references

这篇关于试图避免循环引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:54