Reputation: 512
here is my cypher query :
MATCH (a : User), (user : User {username : 'lebron'})
WHERE a.phoneNumber IN ['757488374748','+9035115','+90390320303']
AND a.username <> 'lebron'
OPTIONAL MATCH (user)-[f:FOLLOWS]->(a), (a)-[p : POSTS]->(b)
RETURN DISTINCT COLLECT(b.postId) AS postId, a.username AS membername,
f.followRequestStatus AS followRequestStatus, user.private AS userPrivate;
'a' node is user node, 'a' can posts photo, follow other users, like other users photo, pretty much like instagram. What's happening here is that it would give followRequestStatus (f.followRequestStatus) correct only if the relation - [p : POSTS] between nodes a and b > exists. If relation 'p' does not exists, it returns null for relation > 'f' also, even if relation f does exist.
Upvotes: 1
Views: 172
Reputation: 30407
Have you tried separating your two OPTIONAL MATCH patterns into two separate OPTIONAL MATCHes?
...
OPTIONAL MATCH (user)-[f:FOLLOWS]->(a)
OPTIONAL MATCH (a)-[p : POSTS]->(b)
...
In the OPTIONAL MATCH description from the developer documentation:
The difference [compared to MATCH] is that if no matches are found, OPTIONAL MATCH will use a null for missing parts of the pattern.
When you use two separate patterns separated by a comma, my assumption is that if both matches are not found, null will be used for all parts of the pattern. Since you want to :FOLLOWS relationships even if there are no :POSTS from a, you need separate OPTIONAL MATCHes.
Upvotes: 3