Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-03-2022 04:56 PM - edited 10-03-2022 04:59 PM
Hello,
I want to map parent child relationship here. I have already added a property "parent" on all child nodes indicating what code has the parent. I'm not sure how to best use that information.
TRACEPARTS:TP01 (Level2CatalogPathID) is parent to TRACEPARTS:TP01002 (Level3CatalogPathID). When I run the below code I create a relationship called parent, but when I check in the database I see parent is two ways. I want to specify parent node <-- child node relation ship in one way.
What I'm I doing wrong here?
//Connect Traceparts Child nodes with Parents Level3
:auto LOAD CSV WITH HEADERS from 'file:///TraceParts-Folder-Structure-Level3.csv' AS row
CALL {
WITH row
CALL apoc.do.when(row.Level2CatalogPathID IS NOT NULL,
'MATCH (c:Traceparts {catalogPathID: row.Level3CatalogPathID})
MATCH (p:Traceparts {catalogPathID: row.Level2CatalogPathID})
MERGE (p)<-[r:parent]-(c)',
'',
{row:row}
)
YIELD value
}
IN TRANSACTIONS OF 1000 ROWS;
I
Level2CatalogPathName | Level2CatalogPathID | Level3CatalogPathName | Level3CatalogPathID |
Mechanical components | TRACEPARTS:TP01 | Bearings | TRACEPARTS:TP01002 |
Mechanical components | TRACEPARTS:TP01 | Bearings | TRACEPARTS:TP01002 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Mechanical components | TRACEPARTS:TP01 | Brakes, clutches and couplings | TRACEPARTS:TP01003 |
Solved! Go to Solution.
10-03-2022 07:54 PM
Don’t see how you get those results from the sample import file. Can you provide the entire file?
an alternative approach would be to use the parent identifier in each node to link them. Generally we don’t store id’s of related nodes, like a foreign key in a real action Al database, because the relationship serves that purpose. Anyways, you could try linking them as follows:
match(n:Traceparts)
where n.parent is not null
match(m:Traceparts)
where m.CatalogPathID = n.parent
merge (m)<-[:parent]-(n)
10-03-2022 07:54 PM
Don’t see how you get those results from the sample import file. Can you provide the entire file?
an alternative approach would be to use the parent identifier in each node to link them. Generally we don’t store id’s of related nodes, like a foreign key in a real action Al database, because the relationship serves that purpose. Anyways, you could try linking them as follows:
match(n:Traceparts)
where n.parent is not null
match(m:Traceparts)
where m.CatalogPathID = n.parent
merge (m)<-[:parent]-(n)
10-04-2022 01:11 AM - edited 10-04-2022 02:27 PM
.
10-04-2022 02:18 PM
I looked at the spreadsheet and still don't know how you got bi-directional relationships. Also, the video is just a still frame. Anyways, glad you were able to solve with the other query.
10-04-2022 02:09 PM
It worked perfectly! Thank you
// Connect Traceparts with Child nodes with Parent nodes
match(n:Traceparts)
where n.parent is not null
match(m:Traceparts)
where m.catalogPathID = n.parent
merge (m)<-[:parent]-(n)
All the sessions of the conference are now available online