I would like to return a composite object from Neo4j, using cypher to clean up my requests.
To give an example, I have a user account object that has permissions saved as relationships. Permissions are complex objects, therefore they cannot be nested, they are now connected by the relation [: HAS_PERMISSION]. What I would like to do is return a complete complex object with already attached permissions, for example, in the example JSON object below
e.g.
permissions:
{
action:'delete',
resource:'blog posts'
}
{
action:'edit',
resource:'users'
}
core user account:
{
username:'Dave',
email:'dave@test.com'
}
What i'd like:
{
username:'Dave',
email:'dave@test.com'
permissions: [{action:'delete', resource:'blog posts'},{action:'edit', resource:'users'}]
}
I currently have a request:
MATCH(user:UserAccount)-[:HasPermission]->(permission:Permission)
WITH {user:user, permissions:collect(permission)} AS UserAccount
RETURN UserAccount
The problem is that this does not quite return what I need, it returns this:
{
user: {
username:'Dave',
email:'dave@test.com'
},
permissions: [{action:'delete', resource:'blog posts'},{action:'edit', resource:'users'}]
}
: , , . , , , ( ).