How to model two nodes related through a third node in neo4j?

时光怂恿深爱的人放手 提交于 2019-12-12 00:42:06

问题


I'm learning Neo4j and currently whiteboarding the scenario i'm thinking of. I have 3 products P1, P2, P3. P1 and P2 are standalone products. P3 is an adapter that helps you connect P1 and P2.

I thought of P1-[connects_to]-P2, with P3 as a property of the connects_to relationship, but then how'd I store P3's properties? if i create all three products as nodes and do P1-[connects_to]-P3 and P2-[connects_to]-P3, that's not really representative of the domain. How do i model this in Neo4j?


回答1:


I think you can use a similar model:

(P1)-[:connected_through]->(A:Adapter)<-[:connected_through]-(P2)

(A)-[:type_is]->(P3)




回答2:


  1. you can also store properties on relationships

  2. Why is creating P3 as a node and connecting it to the others not representative of the domain?

  3. connects_to is a really bad non-descriptive relationship-type, find something in your domain that expresses that relationship better.




回答3:


Have P1, P2 and P3 as nodes (since you said all 3 of them are products) and put P3 with a different label that identifies it as a connecting node.



来源:https://stackoverflow.com/questions/37415193/how-to-model-two-nodes-related-through-a-third-node-in-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!