Hi there, I am trying to create a filetree-like query where I need to get the user's Breadcrumb up the tree. Since we want to implement folder/file sharing, we have to cut the breadcrumb off the moment we have a "broken chain" in the permissions. The data looks like this:
RED -> root folder
GREEN -> folder
BLUE -> user
If we query the bottom folder (green) then we expect the two folders above that to also be in the breadcrumb because the user (blue) :HAS_ACCESS to the folders. But since there is a "broken link" on the first folder, we don't expect to see the Root (red) and the first folder in the Breadcrumb. My query currently looks like this:
MATCH (u:User {ID: 1})-[:HAS_ACCESS]->(folder:Doc:Folder {ID: 2})
OPTIONAL MATCH path = (folder)<-[:PARENT_OF*]-(docs:Doc)
WHERE exists((u)-[:HAS_ACCESS]->(docs))
RETURN path
This returns the full tree:
Not what I'm looking for. Changing the WHERE clause to:
WHERE (u)-[:HAS_ACCESS]->(docs)
Gives an error: Coercion of list to boolean is deprecated. Please consider using
NOT isEmpty(...) instead.
That being said, neither of these options feels like the correct way to go, they were both sort of just a shot in the dark. Are there any good ways to terminate a path at the point where some relationship does not exist?
Bonus question: how does one return just the longest path. Eg. In the case where we have
(f1)-[:PARENT_OF]->(f2)-[:PARENT_OF]->(f3)
I want the path: f1->f2->f3 and not also include f1->f2 as a separate path.
I know the example above is a bit contrived, so take it with a pinch of salt. Thanks in advance!