blujosiB
Convex Community13mo ago
9 replies
blujosi

using convex-ents mapping feature

how do i combine map with afilter or getX(index) . something like
const team = ctx
                .table('teams')
                .get(ctx.viewerX().teamId)
                .map((t: Ent<'teams'>) => {
                    return {
                        team: t.doc(),
                        teamLocations: t.edgeX('teamLocations').docs(),
                        workdaySettings: t.edgeX('workdaySetting').doc(),
                        calendarBlocks: t
                            .edgeX('calendarBlocks')
                            .filter((q: any) => q.gte(q.field('startDate'), Date.now()))
                            .docs(),
                        appointmentTypes: t.edgeX('appointmentTypes').docs()
                    }
                })



or
const team = await ctx.table('teams')
                .filter((q: any) => q.eq(q.field('teamId'), ctx.viewerX().teamId))
                .map((t: Ent<'teams'>) => {
                    return {
                        team: t.doc(),
                        teamLocations: t.edgeX('teamLocations').docs(),
                        workdaySettings: t.edgeX('workdaySetting').doc(),
                        calendarBlocks: t
                            .edgeX('calendarBlocks')
                            .filter((q: any) => q.gte(q.field('startDate'), Date.now()))
                            .docs(),
                        appointmentTypes: t.edgeX('appointmentTypes').docs()
                    }
                })
                .firstx()


should be possible , such that the mapping is on a subset of data instead of the whole table being transversed , when there is a very large dataset.
Was this page helpful?