I have a two-way [:FRIENDSHIP] relationship between User nodes:
(UserA)<-[:FRIENDSHIP {approved:true}]->(UserB)
Here's a little test function in Java to setup the relationship:
public void approveFriendship(User requestor, User requestee) {
Friendship friendship = new Friendship(requestor, requestee);
friendship.setApproved(true);
Friendship invertedFriendship = new Friendship(requestee, requestor);
invertedFriendship.setApproved(true);
requestor.getFriendships().add(friendship);
requestee.getFriendships().add(invertedFriendship);
userRepository.save(requestor);
userRepository.save(requestee);
}
This cypher query returns the friends of UserA, and works fine:
start user=node({0})
match (user)-[r?:FRIENDSHIP]->(friends)
where r.approved = true
return friends
This cypher query returns the posts of a friend, and does not work (returns empty result):
start n=node({0})
match (n)<-[r?:FRIENDSHIP]->(friend)<-[:AUTHOR]-(friendposts)
where r.approved = true
return friendposts order by friendposts.createdAt
When omitting the where r.approved = true
line or changing it to where r.approved = false
it returns posts of friends without the approved status in both cases.
Can anybody spot if I'm doing something wrong here? Much obliged.