Many to many relation filter with _ne

Hi guys,

I have 2 collections called Post and User. In the Post collection i have a done_by many-to-many relation to User.

If a user marked a post as done I save it under done_by.
I can filter done post like this:
ctx.query._where.done_by_user = userId;

But when i try to do this:
ctx.query._where.done_by_user_ne = userId;
to filter post not marked with done, the query doesn’t work. (It works only if the post was marked only with one user.)

How to filter entries with no done_by_user relation? I am using 3.1.4 version of strapi.

Thank you for your answers.

I’m not sure I understand the entire issue here, if the relation to users only has the done_by Strapi isn’t aware of the not_done_by. In this case does this mean every user in the database without a relation? Or is there only a certain group of users?

In your case it sounds like you need another relation for not_done_by so you can request a group of users to do something, then once they have remove them from this relation and move them to the done_by.

As a side point, I generally recommend you avoid the m2m relation if possible and use the manyWay relation instead as m2m can be quite complex and have a significant performance hit. The manyWay relation is on the far right of the relation matrix within in the content-type builder.

Users can mark posts as ‘done’. I need a list of posts which are not marked done by the user. (there is no relation between post and user)

Anyway, thank you for your recommendation, I will check manyWay.

I’m not sure I understand the logic, how do you know the users or what posts need to be done?