Matt LuoM
Convex Community2y ago
4 replies
Matt Luo

Convex Ents: when defining m:m relationships, must the junction table have its own defineEnt()

when defining many to many relationships using Convex Ents, must the junction table have its own defineEnt()?

- If I don't give the junction table its own defineEnt, then I get an error in npx convex dev like:

Argument of type 'myJunctionTable"' is not assignable to parameter of type 'TableNamesInDataModel<EntDataModelFromSchema<SchemaDefinition<{

If I do provide a defineEnt() for the junction table, then I will get the error:
400 Bad Request: FieldsNotUniqueWithinIndex: Hit an error while evaluating your schema:

In table "directMessageChannelMembers": In index "directMessageChannelId": Duplicate field "directMessageChannelId". Index fields must be unique within an index.

If I don't specify the field name in the edges() function, then Convex Ents will use my table name (which is in plural form) to generate the field names. That may be a separate issue, reported here:
support-communityConvex Ents: inconsistent singularization of field names

- Also, if I need to add more columns to the junction table beyond the foreign keys, then it seems I need to give the junction table its own defineEnt()
Was this page helpful?