cancel
Showing results for 
Search instead for 
Did you mean: 

Expand node filtering by relationships properties

Franbr31
Node Link

Hi!!

In my database, I have :TEAM nodes which have :MEMBERSHIP relationships with :PLAYER nodes.

:MEMBERSHIP relationships have isActive property which is a boolean indicating whether the player is active.

I'm using apoc.path.expand() to expand player nodes, but I need to expand filtering by this isActive property.

In the doc I can't find out how to filter by relationship properties, anyone who knows how, or any optimal solution?

Thank you in advance for your comments 🙂

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

I can think of two solutions.  First, you could change your data model to use relationship types to indicate the active status of the membership, such as ACTIVE_MEMBERSHIP and INACTIVE_MEMBERSHIP. You can then use the relationship filtering in apoc.path.expand(). This may be good overall if you routinely search for either active or inactive relationships in your queries.  If you have queries that done query, you will need to use ':ACTIVE_MEMBERSHIP|INACTIVE_MEMBERSHIP' as your relationship type in those queries.

The second option is to filter out those paths that don't meet your criteria after the apoc.path.expand() returns its results. Assuming 'path' represents the result, you can use a predicate like this to filter and return only the paths have isActive true for every relationship.

where all(i in relationships(path) where i.isActive)

View solution in original post

1 REPLY 1

glilienfield
Ninja
Ninja

I can think of two solutions.  First, you could change your data model to use relationship types to indicate the active status of the membership, such as ACTIVE_MEMBERSHIP and INACTIVE_MEMBERSHIP. You can then use the relationship filtering in apoc.path.expand(). This may be good overall if you routinely search for either active or inactive relationships in your queries.  If you have queries that done query, you will need to use ':ACTIVE_MEMBERSHIP|INACTIVE_MEMBERSHIP' as your relationship type in those queries.

The second option is to filter out those paths that don't meet your criteria after the apoc.path.expand() returns its results. Assuming 'path' represents the result, you can use a predicate like this to filter and return only the paths have isActive true for every relationship.

where all(i in relationships(path) where i.isActive)