开发者

Representing a cooking recipe in a graph database

开发者 https://www.devze.com 2023-04-13 03:57 出处:网络
I\'m trying to wrap my head around graph databases.So maybe someone could help explain to me the right way to model this relationship.This is mostly from the perspective of neo4j, but I assume it woul

I'm trying to wrap my head around graph databases. So maybe someone could help explain to me the right way to model this relationship. This is mostly from the perspective of neo4j, but I assume it would be applicable to most graph databases

I have a Recipe node and Ingredient nodes. The Ingredient nodes have a ingredient_in relationship to the Recipe node. The relationship will hold several attributes, of particular note is an amount field with a unit of measure.

I can imagine that elsewhere in the gr开发者_如何学Goaph there would be a UnitOfMeasure nodes that would have converts_to relationships with a conversion ratio.

The point I'm struggling with is how do I represent the Ingredient->Recipe relationship as having a UnitOfMeasure. Coming from RDMS this feels like I need a another node in between, but that feels wrong for a graph database.


It depends on two things:

a) do you have attributed relations or n-ary relations

b) how do you use the units and amounts - possibly a node in between is easier

Imo, using a "normal" design like this

Recipe -- Entry          -- Ingredient
          amount: double
             |
             |
          UniOfMeasure

is fine with Entry being a Node - even if you use a graph database which can handle attributed edges. The design would be quite the same with an attributed n-ary edge btw - the only difference would be that Entry, now possibly named "contains", would be an Edge not a Node.

0

精彩评论

暂无评论...
验证码 换一张
取 消