#Optional one to many relationship (convex-ents)

8 messages · Page 1 of 1 (latest)

subtle pivot
#

Hello,

Is there a way to make an optional one to many relationship using egdes ?
I would like to affect users to a group or no group.

  users: defineEnt({})
  .edge("user_group", { field: "groupId" }),
  user_groups: defineEnt({})
    .edges("users", { ref: "groupId" })
````
elfin walrus
subtle pivot
#

@elfin walrus ok, if I model it without ents, i presume that I won't be able to use the edge methods on this relationship too right ?

#

you answered so fast thank you

elfin walrus
#

I'd probably go with many:many, it will give you the flexibility to later change your design to allow users to be attached to multiple groups.

subtle pivot
#

Hello @elfin walrus any idea on how to replace search since I can't use withSearchIndex with ctx.table ? I mean in convex way. For now I will implement it myself

rough turret
# subtle pivot Hello <@135720781974863872> any idea on how to replace search since I can't use ...

It's so funny i was just researching this stuff just now. The saas-starter has a .searchIndex. Its being used on members.ts like this.

    const query =
      search === ""
        ? ctx.table("teams").getX(teamId).edge("members")
        : ctx
            .table("members")
            .search("searchable", (q) =>
              q
                .search("searchable", normalizeStringForSearch(search))
                .eq("teamId", teamId)
            );

I'm trying to use the complex index and search filtering in the fullstack convex template as guidance and with similar complexity so I'm struggling through trying to do it in ents.