[Convex Ents] Missing inverse edge

Hi got this this error with this code, seems like I missed an inverse edge but I have no clue where and why:
Error fetching POST https://youthful-caribou-100.convex.cloud/api/prepare_schema 400 Bad Request: Error: Hit an error while evaluating your schema:
Uncaught Error: Missing inverse edge in table "messages" for edge "messages" in table "privateChats"
at defineEntSchema (../node_modules/.pnpm/convex-ents@0.7.2_convex@1.11.3_@clerk+clerk-react@5.0.4_react-dom@18.3.1_react@18.3.1__react_3e36zvrjeuxn2krcacprafz7ny/node_modules/convex-ents/src/schema.ts:144:12)
at <anonymous> (../convex/schema.ts:4:28)
Error fetching POST https://youthful-caribou-100.convex.cloud/api/prepare_schema 400 Bad Request: Error: Hit an error while evaluating your schema:
Uncaught Error: Missing inverse edge in table "messages" for edge "messages" in table "privateChats"
at defineEntSchema (../node_modules/.pnpm/convex-ents@0.7.2_convex@1.11.3_@clerk+clerk-react@5.0.4_react-dom@18.3.1_react@18.3.1__react_3e36zvrjeuxn2krcacprafz7ny/node_modules/convex-ents/src/schema.ts:144:12)
at <anonymous> (../convex/schema.ts:4:28)
const schema = defineEntSchema({
privateChats: defineEnt({})
.field("support", v.boolean(), { default: false })
.edges("users", { to: "users" })
.edges("messages"),
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("chats", { to: "privateChats" })
.edges("messages"),
messages: defineEnt({})
.field("content", v.string())
.edge("privateChats")
.edge("users"),
});
const schema = defineEntSchema({
privateChats: defineEnt({})
.field("support", v.boolean(), { default: false })
.edges("users", { to: "users" })
.edges("messages"),
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("chats", { to: "privateChats" })
.edges("messages"),
messages: defineEnt({})
.field("content", v.string())
.edge("privateChats")
.edge("users"),
});
package.json: https://gist.github.com/FleetAdmiralJakob/a56f4a4f6d03c93b0773dd2dc0fbbbcc
Gist
package.json
GitHub Gist: instantly share code, notes, and snippets.
4 Replies
Michal Srb
Michal Srb•10mo ago
Try .edges("messages", {ref: true}) https://labs.convex.dev/convex-ents/schema#1many-edges The error message could be better
Ent Schema - Convex Ents
Relations, default values, unique fields and more for Convex
FleetAdmiralJakob 🗕 🗗 🗙
Thank you for your answer! Did not help. It now looks like this:
const schema = defineEntSchema({
privateChats: defineEnt({})
.field("support", v.boolean(), { default: false })
.edges("users", { to: "users" })
.edges("messages", { ref: true }),
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("chats", { to: "privateChats" })
.edges("messages"),
messages: defineEnt({})
.field("content", v.string())
.edge("privateChats")
.edge("users"),
});
const schema = defineEntSchema({
privateChats: defineEnt({})
.field("support", v.boolean(), { default: false })
.edges("users", { to: "users" })
.edges("messages", { ref: true }),
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("chats", { to: "privateChats" })
.edges("messages"),
messages: defineEnt({})
.field("content", v.string())
.edge("privateChats")
.edge("users"),
});
Michal Srb
Michal Srb•10mo ago
Use singular:
.edge("privateChat")
.edge("user"),
.edge("privateChat")
.edge("user"),
Related: https://github.com/xixixao/convex-ents/issues/21
GitHub
Usability: Table name pluralization in edge() vs edges() is confusi...
I don't think it's very usable to make the table name change pluralization when adding an edge() vs adding an edges(). It seems okay in simple cases: configs: defineEnt({}) .edges("foo...
FleetAdmiralJakob 🗕 🗗 🗙
Where exactly? I already use the singular edge twice in the message ent Wait a minute.... Do I have to use different forms (singular/plural), in the edge parameter of edge() and edges()? I am so confused. Oh man. I got it. Ig
const schema = defineEntSchema({
privateChats: defineEnt({})
.field("support", v.boolean(), { default: false })
.edges("users")
.edges("messages", { ref: true }),
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 }),
messages: defineEnt({})
.field("content", v.string())
.edge("privateChat")
.edge("user"),
});
const schema = defineEntSchema({
privateChats: defineEnt({})
.field("support", v.boolean(), { default: false })
.edges("users")
.edges("messages", { ref: true }),
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 }),
messages: defineEnt({})
.field("content", v.string())
.edge("privateChat")
.edge("user"),
});
This seems to work Thank you Michal But yeah, it was more trial and error than knowing what I did

Did you find this page helpful?