cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Multiple Relationships to the Same Node?

Question: Is it possible to have different types of relationships on the same Node? Or even multiple types of relationships on the same node.

I'm currently modeling out a new graphdb. I plan to have an "Employee" node with ID, Name and a "Country" node (amongst others) with: ID, Country.

I want to be able to have the following relationships: [lives in] and [works in] the [works in] can be multiple countries as employees travel to different places throughout the year.

Possible queries:
Match Employees living in Canada
or
Match Employees working in Spain

Possibility: When viewing a single Employee Node (John Smith) I might see the following relationships:

(Employee: John Smith) Lives In (Country:Canada) Works In (Country: Canada) or
(Employee: John Smith) Lives In (Country:Canada) Works In (Country: Spain), (Country: France)

I'm starting from scratch so I want to build my .csv right the first time.

For another time but for context:

I will also have the following nodes:
(Specialty)
(Language)

I will eventually want to query:
Match (employee) who lives in (country:canada) with (specialty:operations) who speaks (language:french)

1 REPLY 1

Benoit_d
Graph Buddy

Hi Junk,

Everything is possible:

Create (m:Employee{name:'Max'})
Create (j:Employee{name:'John'})
Create (c:Country{name:'Canada'})
Create (u:Country{name:'USA'})

Merge (m)-[:WORKS_IN]->(c)
Merge (m)-[:LIVES_IN]->(u)
Merge (j)-[:WORKS_IN]->(c)
Merge (j)-[:WORKS_IN]->(u)
Merge (j)-[:LIVES_IN]->(c)

Works!

The worthiest advice in order to get quick a good result: fail fast!
Try, see, if wrong, delete & retry as fast as possible.
Don't spend to much time before. Try. Use the saved time after to understand what is wrong.

The second advice:

Match (n) detach delete n

It deletes all nodes and relationships. Database is clean again for the retry.
Have a look at the labels. When trying new thing on a working graph, use separate, new labels. You can re-label afterward. Separate labels make it easier to delete a fail:

Match (n:Employee_test) detach delete n