Reputation: 251
I try to make relationships between an Outfit node and multiple Product nodes. I am able to create a new Outfit node and then create Relationships between this node and the related product nodes. But is there a solution to no this in one query. My opinion is, that I have an array with the product Ids and then create a new outfit node, Match the node by ID for each value in the array and then create a relationship for each.
Do you have any suggestion? This is an example how it should look.
This is my approach, but there is an error with the where ID(a).
UNWIND keys({productIds:[1,2,3] }) AS key
Create (o:outfit {name: "Outfit für heute"})
FOREACH(item IN $list[key]
| Merge(a:article) where ID(a) = item.productIds
| MERGE (o)-[r:includes]->(a)
)
Thank you very much!
Upvotes: 1
Views: 45
Reputation: 9284
The problem is you are using MERGE
for article
instead of MATCH
, and you cannot use MATCH
within a FOREACH
, also you are UNWINDING
keys of a map, but you are not fetching that key value. It can be done simply like this, using IN
operator:
Create (o:outfit {name: "Outfit für heute"})
WITH o
MATCH (a:article) where ID(a) IN [1, 2, 3]
MERGE (o)-[r:includes]->(a)
Upvotes: 1