Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-12-2019 05:56 AM
Hi
I have a relationship between a vessel and a product (vessel)-[:HasInventory]->(product) when I forecast what a vessel may need to complete the voyage I get other products back plus products that the vessel may own, I don't want to add a forecasted relationship between any product the vessel where it has a [:HasInventory] relationship, can I do this completely in cypher or is it better I just take the nodes back iterate and add the [:Forecasted] as I go?
regards
Solved! Go to Solution.
01-13-2019 04:52 PM
Hi,
Existing relationship:
Add 'ForeCasted' relationship to the vessel node. Here is the sample that I created:
MERGE(v:Vessel {name:"V1"})
MERGE(p:Product {name:"P1"})
MERGE(p1:Product {name:"P2"})
MERGE (v)-[:HasInventory]->(p)
MERGE (v)-[:ForeCasted]->(p1);
Result:
MATCH (v)-[:HasInventory]->(p)
OPTIONAL MATCH (v)-[:ForeCasted]->(p1)
RETURN v.name as Vessel, p.name as HasInventory, p1.name as Forecasted ;
Result:
Add this 'ForeCasted' relationship only if the vessel has any forecast products.
-Kamal
01-13-2019 04:52 PM
Hi,
Existing relationship:
Add 'ForeCasted' relationship to the vessel node. Here is the sample that I created:
MERGE(v:Vessel {name:"V1"})
MERGE(p:Product {name:"P1"})
MERGE(p1:Product {name:"P2"})
MERGE (v)-[:HasInventory]->(p)
MERGE (v)-[:ForeCasted]->(p1);
Result:
MATCH (v)-[:HasInventory]->(p)
OPTIONAL MATCH (v)-[:ForeCasted]->(p1)
RETURN v.name as Vessel, p.name as HasInventory, p1.name as Forecasted ;
Result:
Add this 'ForeCasted' relationship only if the vessel has any forecast products.
-Kamal
01-15-2019 04:20 AM
Thanks, I ended up omitting the hasholding items from the spatial intersect and just applying the appropriate relationship to the results
WITH "LINESTRING(6.1709 42.8694,5.90065916861194 43.0423602080088)" as route CALL spatial.intersects('productsgeom', route) YIELD node WHERE NOT (:Vessel{mmsi:248291000})-[:HasHolding]-(node) return node
All the sessions of the conference are now available online