neo4j - Relationship between three nodes

旧巷老猫 提交于 2019-12-07 13:51:04

问题


I'm totally new to Neo4j and I'm testing it in these days. One issue I have with it is how to correctly implement a relationship which involves 3 different nodes using Spring Data. Suppose, for example, that I have 3 @NodeEntitys: User, Tag and TaggableObject.

As you can argue, a User can add a Tag to a TaggableObject; I model this operation with a @RelationshipEntity TaggingOperation. However, I can't find a simple way to glue the 3 entities inside the relationship. I mean, the obvious choice is to set @StartNode User tagger and @EndNode TaggedObject taggedObject; but how can I also add the Tag to the relationship?


回答1:


This is called a "hyperedge", I believe, and it's not something that Neo4j supports directly. You can create an additional node to support it, tough. So you could have a TagEvent node with a schema like so:

(:User)-[:PERFORMED]->(:TagEvent)
(:Tag)<-[:USED]-(:TagEvent)
(:TagObject)<-[:TAGGED]-(:TagEvent)

Another alternative is to store a foreign key as a property on a relationship or a node. Obviously that's not very graphy, but if you just need it for reference that might not be a bad solution. Just remember to not use the internal Neo4j ID as in future versions that may not be dependable. You should create your own ID for this purpose.



来源:https://stackoverflow.com/questions/29613795/neo4j-relationship-between-three-nodes

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