I have two unwinds, that create some relationships and nodes, but if the list for the first unwinds is empty, the second unwind doesn't execute.
How can I fix that?
CALL apoc.periodic.iterate(
"
UNWIND $POSTS as post
RETURN post
",
"
MERGE (p:Post{id: post.id})
WITH p, post
UNWIND post.tags as value
MERGE (t:Tag{tag: value})
MERGE (t)-[:has_tag]->(p)
WITH p, post
UNWIND post.user_mentions as user_mention
MERGE (u1:User{id: user_mention})
MERGE (p)-[:mentions]->(u1)
",
{batchSize: 500, params: {POSTS: $POSTS}, iterateList:true}
)
Example results
Parameters, with non-empty tags
[
{
"id": 123,
"tags": [1],
"user_mentions": [123, 234],
}
]
Graph created in database - Expected result
Parameters, with empty tags
[
{
"id": 123,
"tags": [],
"user_mentions": [123, 234],
}
]