Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-03-2019 04:22 AM
I'm running Neo4j Community v.3.5.7 on a Mac.
I have a schema that looks something like this:
(:Person { Name: Name, FullName: FullName, Level: Level, Strength: Strength})
(:Strength {Name: Strength})
When I do a query,
MATCH (p:Person),(s:Strength)
WHERE p.Strength = s.Name AND p.Strength = "Responsibility"
CREATE (p)-[r:Responsibility]->(s)
RETURN p,s
I see this:
How do I get the relationship 'lines' (e.g. labeled as "Responsibility") to be labeled with the Person's "Level" (an integer value property from the Person schema) instead of the name of the relationship?
Solved! Go to Solution.
07-04-2019 01:27 AM
Use apoc.create.relationship for this.
As the 'Level' property values are integers you will have a problem in selecting the relationship as the relationship label has to be a string. Here are the workarounds for this problem,
MATCH (p:Person),(s:Strength)
WHERE p.Strength = s.Name AND p.Strength = "Responsibility"
WITH p, s
CALL apoc.create.relationship(p, toString(p.Level), {}, s) YIELD rel
RETURN p, s;
To select relationship "8" workaround:
MATCH (p:Person)-[r]-(s)
WHERE Type (r) = "8"
RETURN p, s;
MATCH (p:Person),(s:Strength)
WHERE p.Strength = s.Name AND p.Strength = "Responsibility"
WITH p, s
CALL apoc.create.relationship(p, ("S" + toString(p.Level)), {}, s) YIELD rel
RETURN p, s;
You can easily filter by relationship type:
MATCH (p:Person)-[:S8]-(s)
RETURN p, s;
Hope this works for you.
07-03-2019 06:45 AM
Hello Steve and welcome to the community!
The level/strength properties are set for the nodes in your example. If you want the same properties for the relationships, you would simply use the SET clause to set the values. Also, I would recommend you use Merge for creating the relationships to ensure you do not create duplicate relationships.
For example:
MATCH (p:Person),(s:Strength)
WHERE p.Strength = s.Name AND p.Strength = "Responsibility"
MERGE (p)-[r:Responsibility]->(s)
SET r.Strength = "xxx"
RETURN p,s
This will set the property for the relationship. Ideally you do not want to duplicate data (node property/relationship property) in the graph.
Elaine
07-03-2019 07:11 AM
Thanks, but "Responsibility" still shows up as the label for the relationship - I want it to display the Person's "Level" instead.
07-04-2019 01:27 AM
Use apoc.create.relationship for this.
As the 'Level' property values are integers you will have a problem in selecting the relationship as the relationship label has to be a string. Here are the workarounds for this problem,
MATCH (p:Person),(s:Strength)
WHERE p.Strength = s.Name AND p.Strength = "Responsibility"
WITH p, s
CALL apoc.create.relationship(p, toString(p.Level), {}, s) YIELD rel
RETURN p, s;
To select relationship "8" workaround:
MATCH (p:Person)-[r]-(s)
WHERE Type (r) = "8"
RETURN p, s;
MATCH (p:Person),(s:Strength)
WHERE p.Strength = s.Name AND p.Strength = "Responsibility"
WITH p, s
CALL apoc.create.relationship(p, ("S" + toString(p.Level)), {}, s) YIELD rel
RETURN p, s;
You can easily filter by relationship type:
MATCH (p:Person)-[:S8]-(s)
RETURN p, s;
Hope this works for you.
07-04-2019 03:09 PM
F-A-N-T-A-S-T-I-C !!
I used 2: Prefix Level value with letter "S" and it was the perfect answer for what I was trying to accomplish.
Thank you so much for your time and trouble
All the sessions of the conference are now available online