'match, iterate, create and create relationship assistance

Using this pseudo code, how can I do this entirely in cypher?

match-all nodes with the property of type: Images

using properties from the original match

match using the properties from the main match for type: Parent nodes

if no nodes of the parameters with the type: Parent create a new node using the parameters and type: Parent

match using the properties from the main match for type: Parent nodes

create a parent -> image relationship, using the node from the initial match and the match for type: Parent node



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source