I have some records on lavles Employee and its Child labels
Label : Employee | Member| Manager| Lead - An employee can act as either of (Member, Lead, Manager) at the same time for different project Id
Consider now i have a list in java/.net extracted from json . I need to match the type from it and then create a relationship below
{
PersonID : 12345,
PersonName : Test1,
{
"ProjectName": "Project1",
"ProjectId": "1000",
"type": "Lead",
},
{
"ProjectName": "Project2",
"ProjectId": "1001",
"type": "Manager",
},
{
"Project": "Project3",
"ProjectId": "1002",
"type": "Member",
},
}
(person: Employee{PersonID}) - [t:LeadFor]->(ld:Lead {ProjectId})
(person: Employee{PersonID} )- [t:MemberFor]->(m:Manager{ProjectId})
(person: Employee{PersonID} )- [t:ManagerFor]->(m:Member {ProjectId})
I can iterate the list in my code , match the type in the if else statement and create a relationship, but when i have the whole list i want to dynamically through cypher
If you have installed APOC, then an easy approach is to use apoc.create.relationship().
Here is how I approached it using your JSON file. (Note: I modified it slightly to include a people and projects reference to make it easier to go through the file)
WITH 'employee-project.json' AS url
CALL apoc.load.json(url) YIELD document
UNWIND document.people AS person
UNWIND document.projects AS project
MERGE (emp:Employee {person_id:person.PersonID})
ON CREATE
SET emp.person_name = person.PersonName
MERGE (pro:Project {project_id: project.ProjectID})
ON CREATE
SET pro.project_name = project.ProjectName
CALL apoc.create.relationship(emp, project.type, {}, pro) YIELD rel
RETURN rel
Thanks!
This is somewhat i was looking for. but for me i have extracted json object and i already have projects (as above) object with me in my program(which has inner key value), how can i create using apoc.create.relationship or other way?.
Yes, I have both project node created already, and also the employee node will also get created before i execute this query on top. I have both the nodes already. now based on the fields inside the list (lead, member, manager), i need to create that relationship with the matching (emp:Employee) --[Manager/Member/Lead]-(pro:Project)