How to "include" relation properly?
is this the best way in convex to "include" an author name?

4 Replies
Yep, that's the way, but it can be less formal
but this needs so many db calls, can't this be optimized?
It seems to be a lot of calls compared to a sql command or orm because the api is low level, eg., it doesn't perform joins for you automatically. But sql and orm's are still doing this many db calls for joins under the hood, you're just not exposed to the semantics.
Here you're fetching n records and then +1 for each author. You could start trying to optimize by, eg., stashing the authors in an array and checking there before a db call, but Convex is already doing that kind of caching for you under the hood. Most attempts to optimize early end up being wasted with Convex because they've thought through so much of this in the api design. I have a ton of premature optimization in my own code that will probably just always be there now lol.
My recommendation is resist the urge to optimize, and just write code that works. Then see how it performs in practice. Not having to think about so much is a massive benefit of using Convex.
I see!
thank you so much for this!