Parse.Query.or empty results

Hey guys,

I have following situation:

I have posts in a timeline. Posts can be public (for every user) or for specific groups.
The post has a column “groups” which holds the array of the groups. and a boolean “public”.
When public is true, the groups are an empty array.
when groups are set, public is false.

When I fetch the posts, I wrote a beforeFind Hook in the cloud code.

I clone the incoming query (which has some other flags like “isPinned”) and to one query I add the constrain to the groups (so users only get the posts from his group) on the second query I add the constrain for public = true.

I chain them with Parse.Query.or but I get empty results.

So goal is, that I get all public posts and all posts for the groups. Each query for themselves are working. But chaining them with the or doesn’t work.

Can you help? Is the Parse.Query.or working different?

Thanks!

Why don’t you store public field in the group array. With this way you can reduce query to one.

For example post is public you can set public value to groups array like this:
[“PublicPost”]

If post is not public then you can set group as normal like this
[“groupA”…]

And when you query you do this
query.containedIn("groups",["PublicPost","groupF"...]);

With this way you reduce query count and get rid of chained queries. And you get both public posts and posts from users groups.

Yeah we tried this. But in the group array we have pointers. And somehow this throws and error.
We store pointers for easier access and less queries in the fronend.

Did you tried to use imaginary group? For example:

const group = new Parse.Object("Group",{id:"PublicPost"});

Does error happens because you use include("groups") but imaginary group object doesn’t exist?

I think it would be easier to use ACL instead, but if you want to share your query that is not working as expected I can try to help.