With above query I am trying to create role and its relationship with permission. The query returns role in above case but if i make array empty in where condition, it creates role but does not return it. Please refer below query for the same.
create (role:ROLE {slug:"abc1"})
with role
match (permission:PERMISSION)
where permission.name IN []
merge (role)-[:HAS_PERMISSION]->(permission)
RETURN role;
I need to return created role node in both the cases. Need help here.
True, you need a with between a create and a call. You should also need the with in the call subquery to make the ‘role’ node available within the call subquery. Your merge will create a new node otherwise.