I’m trying to filter a list based on relationships and am quite stumped. Any advice would be much appreciated!
Since my app is quite complicated (lots of collections) intertwined, I’ve tried to make this as simple as possible through an example.
Database premise
- Let’s say I have the collections: users, posts, and fruits.
- Users are related to fruit, such that they can pick which ones they like, e.g. apples and oranges, but not bananas or pears.
- Users are related to posts, as people can write posts and are designated the author.
- Users are related to other users, as people can essentially friend each other.
- Posts are related to fruit, as the post author can choose what fruit a post is about (e.g. bananas and oranges).
What I am trying to do
I have a timeline in which users can see posts authored by their friends. This part is the easy part.
Here’s the challenging part. I want users to only see posts about fruit they like. For example, if I like apples and bananas, I want to only see posts about apples and bananas but I do not want to see posts about apples or apples and pears, etc.
I’m essentially wondering if I can filter lists based on having a matching relationship, i.e. the fruit I like are the same as fruit the post is about. Is this possible? Are there any work arounds really grateful if anyone has any tips!