I have one relationship type (exported products from one country to another) named "EXPORTED_PRODUCT". On top of that i've created second relationship type based on the product code, as stated here:
MATCH (c1:Country)-[r:EXPORTED_PRODUCT]->(c2:Country) WHERE r.ProductHSCode="300220" MERGE (c1)-[:EXPORTED_PRODUCT_300220]->(c2)
Eveything looks fine, expect that any other link property, such as "ProductValue" and "ProductQuantity" don't copy at all.
Any ideas how can i duplicate these properties to the new relationship type?
SET r2 = r1
Need to be tested not sure, you need to create the r2 variable for your new relation as you did with the first one
Hi @tard_gabriel can you please make an example with the Cypher query? I'm not quite sure how to replicate what you've described...
@tard_gabriel it's not working. I've even tried with "WHERE r1.ProductHSCode="300220"" but no success whatsoever. Any other ideas perhaps?
for some reason your query returns "(no changes, no records)", but this works:
It's simply because your relation already exist, that's why it's ON CREATE SET.
It will copy r1 in r2 only if the relation is created, if you want to do it systematically, your query is right. If you want to do it only when it matches an existing relationship you can use ON MATCH SET, so to recap you have :
ON CREATE SET
ON MATCH SET
You also use both ON CREATE and ON MATCH when you need to define a different behaviour for each of them.
I would like to note that creating a new relationship type for each product is not a good practice. The property ProductHSCode on the relation EXPORTED_PRODUCT is quite sufficient to distinguish that. You just duplicate information with creating those new relations.
To clarify this exactly, we would need to know the full use case for these relationships and how they are queried later.
Indeed, @Reiner got a point you won't be able to generalise a query and optimise it with parameters.