Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-14-2020 02:07 AM
I have four "generic labels":
Now I want to connect these nodes to my Car nodes.
But I don't want to connect them straight onto to it. I first connect them to a Combo node and then that is connected to the Car.
So, I first need to make sure the "generic" nodes exists, then make sure the "combo" node exists and then make sure the "combo" node is connected to the car.
I tried this
with 13900 as engineCapacity, 160 as horsePower, 'automatic' as transmission, 5 as nDoors
merge (engineNode:EngineCapacity {value:engineCapacity})
merge (hpNode:HorsePower {value:horsePower})
merge (transNode:Transmission {value:transmission})
merge (doorsNode:NumberOfDoors {value:nDoors})
merge (carNode:Car {value:'VW Golf mk6 1.4 TSI 160BHP'})
with engineNode, hpNode, transNode, doorsNode, carNode
merge (combo:Combo)<-[:IN_COMBO]-(engineNode),
(combo)<-[:IN_COMBO]-(hpNode),
(combo)<-[:IN_COMBO]-(transNode),
(combo)<-[:IN_COMBO]-(doorsNode),
(combo)-[:SPECIFIES_CAR]->(carNode)
which obviously doesn't work.
Then I tried
with 13900 as engineCapacity, 160 as horsePower, 'automatic' as transmission, 5 as nDoors
merge (engineNode:EngineCapacity {value:engineCapacity})
merge (hpNode:HorsePower {value:horsePower})
merge (transNode:Transmission {value:transmission})
merge (doorsNode:NumberOfDoors {value:nDoors})
merge (carNode:Car {value:'VW Golf mk6 1.4 TSI 160BHP'})
with engineNode, hpNode, transNode, doorsNode, carNode
match (combo:Combo)<-[:IN_COMBO]-(engineNode),
(combo)<-[:IN_COMBO]-(hpNode),
(combo)<-[:IN_COMBO]-(transNode),
(combo)<-[:IN_COMBO]-(doorsNode),
with count(combo) as counter, engineNode, hpNode, transNode, doorsNode, carNode
case counter
when 0 then create(combo2:Combo)<-[:IN_COMBO]-(engineNode),
(combo2)<-[:IN_COMBO]-(hpNode),
(combo2)<-[:IN_COMBO]-(transNode),
(combo2)<-[:IN_COMBO]-(doorsNode)
end
merge (combo2)-[:SPECIFIES_CAR]->(carNode)
which again doesn't work.
Any ideas how to handle this?
Thanks
Solved! Go to Solution.
04-14-2020 03:31 AM
Thanks for providing good amount of details in your question. But it'd be more helpful if you could provide the errors you're getting in both the ways.
Btw, for now I solved it by merging each relation separately.
with 13900 as engineCapacity, 160 as horsePower, 'automatic' as transmission, 5 as nDoors
merge (engineNode:EngineCapacity {value:engineCapacity})
merge (hpNode:HorsePower {value:horsePower})
merge (transNode:Transmission {value:transmission})
merge (doorsNode:NumberOfDoors {value:nDoors})
merge (carNode:Car {value:'VW Golf mk6 1.4 TSI 160BHP'})
with engineNode, hpNode, transNode, doorsNode, carNode
merge (combo:Combo)<-[:IN_COMBO]-(engineNode)
merge (combo)<-[:IN_COMBO]-(hpNode)
merge (combo)<-[:IN_COMBO]-(transNode)
merge (combo)<-[:IN_COMBO]-(doorsNode)
merge (combo)-[:SPECIFIES_CAR]->(carNode)
Hope it helps
04-14-2020 03:31 AM
Thanks for providing good amount of details in your question. But it'd be more helpful if you could provide the errors you're getting in both the ways.
Btw, for now I solved it by merging each relation separately.
with 13900 as engineCapacity, 160 as horsePower, 'automatic' as transmission, 5 as nDoors
merge (engineNode:EngineCapacity {value:engineCapacity})
merge (hpNode:HorsePower {value:horsePower})
merge (transNode:Transmission {value:transmission})
merge (doorsNode:NumberOfDoors {value:nDoors})
merge (carNode:Car {value:'VW Golf mk6 1.4 TSI 160BHP'})
with engineNode, hpNode, transNode, doorsNode, carNode
merge (combo:Combo)<-[:IN_COMBO]-(engineNode)
merge (combo)<-[:IN_COMBO]-(hpNode)
merge (combo)<-[:IN_COMBO]-(transNode)
merge (combo)<-[:IN_COMBO]-(doorsNode)
merge (combo)-[:SPECIFIES_CAR]->(carNode)
Hope it helps
04-14-2020 04:01 AM
Wow it works
I can't believe it was that simple as it took me a couple of hours and I gave up.
It's just a concept to begin with which I'm not sure I'm going to use.
Thanks!
04-14-2020 07:17 AM
Glad I could help 🙂
All the sessions of the conference are now available online