#[Convex Ents] Problems with inverse field

14 messages · Page 1 of 1 (latest)

scenic crow
#

Hi, I want to create another edge to my table to another table which keeps track of which user read a message so I first added the edge like that:

  users: defineEnt({})
    .field("clerkId", v.string(), { unique: true })
    .field("username", v.string(), { unique: true })
    .field("firstName", v.optional(v.string()))
    .field("lastName", v.optional(v.string()))
    .edges("privateChats")
    .edges("messages", { ref: true })
    .edges("readMessages", { to: "messages" }),

  messages: defineEnt({})
    .field("content", v.string())
    .field("deleted", v.boolean(), { default: false })
    .edge("privateChat")
    .edge("user")
    .edges("readBy", { to: "users" }),

With that I got this error: Error: Hit an error while evaluating your schema: Uncaught Error: Specify `table` if you're customizing the `field` or `inverseField` for a many:many edge. Config: `{"to":"messages","inverseField":"readBy"}`

So I added the inverseFields:

  users: defineEnt({})
    .field("clerkId", v.string(), { unique: true })
    .field("username", v.string(), { unique: true })
    .field("firstName", v.optional(v.string()))
    .field("lastName", v.optional(v.string()))
    .edges("privateChats")
    .edges("messages", { ref: true })
    .edges("readMessages", { to: "messages", inverseField: "readBy" }),

  messages: defineEnt({})
    .field("content", v.string())
    .field("deleted", v.boolean(), { default: false })
    .edge("privateChat")
    .edge("user")
    .edges("readBy", { to: "users", inverseField: "readMessages" }),

So now I got this error: ```Error: Hit an error while evaluating your schema:
Uncaught Error: Specify table if you're customizing the field or inverseField for a many:many edge. Config: {"to":"messages","inverseField":"readBy"}


I tried some other stuff too but I weren't able to get it working, this is one of my attempts.

Could someone tell me how I can build this thing?
queen forumBOT
#

Hi @scenic crow. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the knowledge sources provided, it seems like you're trying to create a many-to-many relationship between users and messages tables. However, the error messages suggest that you need to specify the table if you're customizing the field or inverseField for a many:many edge.

Unfortunately, the knowledge sources do not provide a direct solution to your problem. However, they do provide some insights into how to define edges and inverse edges in Convex Ents.

For instance, in the Discord support thread: [Convex Ents] Missing inverse edge (https://discord.com/channels/1019350475847499849/1239185755465846864), a user had a similar issue with defining edges. The solution was to use singular forms in the edge() method and plural forms in the edges() method.

However, this might not directly apply to your case as you're dealing with a many-to-many relationship and the error message suggests that you need to specify the table in your configuration.

I would recommend checking the Convex documentation or reaching out to the Convex support for more specific guidance on how to define many-to-many relationships in Convex Ents.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@scenic crow kapa.ai is still learning and improving, please let us know how it did by reacting below

scenic crow
#

Hi, added the tables:

  users: defineEnt({})
    .field("clerkId", v.string(), { unique: true })
    .field("username", v.string(), { unique: true })
    .field("firstName", v.optional(v.string()))
    .field("lastName", v.optional(v.string()))
    .edges("privateChats")
    .edges("messages", { ref: true })
    .edges("readMessages", {
      to: "messages",
      inverseField: "readBy",
      table: "messages",
    }),

  messages: defineEnt({})
    .field("content", v.string())
    .field("deleted", v.boolean(), { default: false })
    .edge("privateChat")
    .edge("user")
    .edges("readBy", {
      to: "users",
      inverseField: "readMessages",
      table: "users",
    }),

Now get this error: Uncaught Error: Missing inverse edge in table "messages" for edge "readMessages" in table "users"

#

@queen forum

queen forumBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Sorry @scenic crow, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:

Perhaps try again in 15mins?

scenic crow
#

@queen forum

queen forumBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Sorry @scenic crow, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:

Perhaps try again in 15mins?

pliant isle
scenic crow
#

Wait. I think I got it