How to add multiple relationships with property filter of each relationship?

(Abhishinde01) #1
MATCH (me)-[post_rel_source:FOLLOWS_TEAM|:FOLLOWS|:FOLLOWS_EVENT*0..1]->(user)

In above case how can I check different 'status' of all 3 relations?
FOLLOWS_TEAM has accepted:1
FOLLOWS has accepted:1
FOLLOWS_EVENT dont have any status.

If I add like following, its not working for 'FOLLOWS_EVENT'


(M. David Allen) #2

The way you've stated your query, you're asking for a single relationship with multiple types, which won't work because such a relationship can't exist in Neo4j. The way to do what you want is to break out the match 3 ways, and then use WHERE conditions. Like this:

MATCH (me)-[r1:FOLLOWS_TEAM]->(user)
MATCH (me)-[r2:FOLLOWS]->(user)
MATCH (m3)-[r3:FOLLOWS_EVENT]->(user)
WHERE r1.accepted = 1 AND r2.accepted = 1

Notice that this treats the three different relationships as all separate. Take care to make sure you're matching the right user (those three different relationships could go to different users). Finally, I can't help with how to express "don't have any status" on FOLLOWS_EVENT because this depends on what you mean by status. Maybe you want WHERE r3.accepted IS NULL.

(Abhishinde01) #3

This looks promising
But In this case 'user' node is not showing combination of all 3 MATCH outputs.

(M. David Allen) #4

I'm not sure what you mean. It'd be helpful to post the entire query, what its output is, along with what you expect the output to be.

(Abhishinde01) #5

My problem statement is

me FOLLOWS_TEAM {isaccepted=1} team
me FOLLOWS {isaccepted=1} user
me FOLLOWS {isaccepted=1} event
me FOLLOWS_ORG {isaccepted=1} Org

I want list post of user+teams+org's all teams to whom 'me' is following.

I came up with following solution

MATCH (me:User)-[f:FOLLOWS_ORG*0..1{requeststatus:1}]->(org)-[post_rel_source:FOLLOWS_TEAM|:FOLLOWS|:EVENTS_OF_ORG*0..1]->(users)- [post_rel:POSTED]->(mypost:Wallpost)
WHERE me.userid='32387'  
RETURN me,users,mypost;

but in this query, I want to check weither user / team / Event/org has accepted my follow request.
EVENTS_OF_ORG this relation dont have any status.
NOTE - If 'me' is following 'Org', we no need to check status.

(Andrew Bowman) #6

In this case we may need to use predicates to filter to the right relationships, which means breaking this big match down:

MATCH (me:User)-[:FOLLOWS_ORG*0..1{requeststatus:1}]->(orgOrUser)
WHERE me.userid='32387' 
MATCH (orgOrUser)-[post_rel_source:FOLLOWS_TEAM|:FOLLOWS|:EVENTS_OF_ORG*0..1]->(users)- [:POSTED]->(mypost:Wallpost) 
WHERE size(post_rel_source) = 0 OR type(post_rel_source[0]) = 'EVENTS_OF_ORG' OR post_rel_source[0].requeststatus = 1
RETURN me, users, mypost;