Ents - How to define composite index?
I'm not sure how I can do composite indexes? I have a reactions table which I want to find all reactions by memeId and userId
5 Replies
I think something like this.

is this the way I should be doing it?
I'm using Ents
not the stanrdard convex approach
Ah. Ok. Not sure.
I am not familiar with ents. But I think fundamentally if you want to query the "reactions" table with a different index then you'd have to query that table directly. I believe all
.edge
is doing underneath is using the indexes Ents creates automatically to query the necessary tables.
Otherwise you're trying to use two indexes at once to query the table.
@Michal Srb can correct my understanding@Web Dev Cody you can either traverse one of the edges, or create an index as @thedevstockgirl suggested. With Ents you can do practically everything you can do with Convex, and sometimes a custom index is the way to go. I did the same with the "teamAndUser" index on my "members" table in the saas-starter.
If "reactions" don't have any fields besides memeId and userId though, you can model them as a many:many edge between memes and users. You can then do
This will use the "composite" index under the hood (but only returns a boolean, since there's currently no way to have other information stored on the many:many edge). I'll think about if I can unlock this use case as I it's probably fairly common.