𝗠𝗜𝗖𝗞𝗘𝗬
𝗠𝗜𝗖𝗞𝗘𝗬
CCConvex Community
Created by 𝗠𝗜𝗖𝗞𝗘𝗬 on 11/23/2024 in #support-community
[Ents]: Ordering on Edge
Hello all, I have a question which in short is whether (or rather how) it's possible to order the query of many:many edges on the other end of the edge using convex-ents. I have user ents which can "attend" events ents - i.e. many:many relationship. I want to query the events a single user is attending and in the same query order the retrieved events based on the start date of the events (in the db as a string, like 2025-01-24T12:30:00.000+01:00) as follows:
await table("users")
.getX(userId)
.edge("attendingEvents")
.order("asc", "by_startdate");
await table("users")
.getX(userId)
.edge("attendingEvents")
.order("asc", "by_startdate");
The events schema contains an index for "startdate". But my retrieved results are never ordered by the startdate. My current solution looks like this:
const events = await table("users")
.getX(userId)
.edge("attendingEvents");

return events
.filter(({ startdate }) => startdate >= today.toISOString())
.sort((a, b) => a.startdate.localeCompare(b.startdate))
.splice(0, take);
const events = await table("users")
.getX(userId)
.edge("attendingEvents");

return events
.filter(({ startdate }) => startdate >= today.toISOString())
.sort((a, b) => a.startdate.localeCompare(b.startdate))
.splice(0, take);
Perhaps there is a more efficient way to do this since I'm filtering out the results that have a startdate in the past anyway. Any help would be highly appreciated 🙂
5 replies
CCConvex Community
Created by 𝗠𝗜𝗖𝗞𝗘𝗬 on 4/7/2024 in #support-community
Convex Ents 1:many rel
Hey! I'm playing around a bit with Convex Ents and I'm running into an issue which I don't know if it's due to my lack of understanding how edges works. I've got two tables with a 1:many relationships, organisers can have many events or none, and events can have one organiser or none. So my idea was this:
events: defineEnt({[...]})
.edge("organiser", { optional: true }),
organisers: defineEnt({[...]})
.edges("events")
events: defineEnt({[...]})
.edge("organiser", { optional: true }),
organisers: defineEnt({[...]})
.edges("events")
Getting no TS warnings in my IDE, but when saved I get this response from the CLI:
[1] Uncaught Error: Unexpected inverse edge type organiser, events
[2] at defineEntSchema (../../../node_modules/convex-ents/src/schema.ts:115:12)
[3] at <anonymous> (../convex/schema.ts:5:20)
[1] Uncaught Error: Unexpected inverse edge type organiser, events
[2] at defineEntSchema (../../../node_modules/convex-ents/src/schema.ts:115:12)
[3] at <anonymous> (../convex/schema.ts:5:20)
Am I doing something wrong or is it simply impossible for the singular edge to be optional? I noticed the docs say that optional 1:1 are not supported but I figured this is a 1:many so it might not apply.
6 replies