Use node-data in relation


#1

I just started with neo4j and did some research, but couldn't find any satisfying solution for the following:

Create (p1:Person{name:'Max'})
Create (p2:Person{name:'Sarah'})
Create (sc:Company{name:'SuperCompany'})
Create (su:University{name:'Some University'})
Create (p1)-[:works]->(sc)

Create (p1)-[:studies]->(su)
Create (p2)-[:studies]->(su)

Create (p1)-[:knows]->(p2)

neo4j

I want to add the information, where Sarah and Max first met. In this example it would be the node "Some University". So my first thougt was simply adding a property to the "knows"-relation which links to the node- which isn't possible.

What is the best practise to solve this issue?


(Michael Hunger) #2

You have two options here, depending on how frequent that requirement is and if the "concept" of the "friendship" is important enough to be it's own entity in your domain.

  1. you can just store the "primary key" of a :Location node in a property and look it up when needed. As you can use multiple labels on an entity you could tag universities, coffee-shops, parks etc. as Locations

  2. if the friendships is an important enough concept, you can turn it into a node and then link whatever extra information you need to that node.

HTH


#3

Thank you michael. I think the second solution is more practicable in my use case, so I built the following:

Create (p1:Person{name:'Max'})
Create (p2:Person{name:'Sarah'})
Create (sc:Company{name:'SuperCompany'})
Create (su:University{name:'Some University'})
Create (p1)-[:works]->(sc)

Create (p1)-[:studies]->(su)
Create (p2)-[:studies]->(su)

Create (fs:FriendShip{started:date()})
Create (fs)-[:first_met]->(su)
Create (p1)-[:belongs]->(fs)
Create (p2)-[:belongs]->(fs)

Doesn't look clean as before, but it works.