get-convex / convex-ents

https://labs.convex.dev/convex-ents
25 stars 5 forks source link

m:m relationship .has() function always returning true #38

Closed lbybrilee closed 3 days ago

lbybrilee commented 2 months ago

I have a many to many relationship defined where there are many users to many groups.

I need to find groups that the user has not joined. However, the isJoined variable from the below code is always returning true for all groups/all users. Is this a bug or am I doing something wrong?

export const getNotJoined = query({
  handler: async (ctx) => {
    const user = await getAuthUserId(ctx);
    console.log(user);

    if (!user) {
     return null;
    } else {
      const groups = await ctx
        .table("groups")
        .order("desc", "userCount")
        .filter((q) => q.not(q.field("administrative")))
        .filter((q) => q.field("approved"))
        .take(20)
        .map(async (q) => {
          const isJoined = await ctx.table("users").get(user).edge("groups").has(q._id);
          console.log(isJoined);
        });

      return groups.filter(Boolean);
    }
  },
});

My schema is pretty basic. Each entity has a .edge("user) and vise versa on it.

I also checked const isJoined = await ctx.table("users").get(user).edge("groups") <- this part and it gives me back the correct groups, so I'm pretty sure that it has to do with the has function.

meenie commented 3 weeks ago

This should be fixed by https://github.com/get-convex/convex-ents/pull/39

xixixao commented 3 days ago

Fixed by #39