swajp
swajp•16mo ago

get name by id

i am new to convex and i would love to get barber's name fro my schema and if i am mapping it i can access only to the barber _id
No description
3 Replies
swajp
swajpOP•16mo ago
thats what i have for now
No description
erquhart
erquhart•16mo ago
Hey @swajp, welcome! You'll want to loop/map over your result and fetch each barbert to get the names.
const barberSubservices = await ctx.db
.query('subServicesByBarber')
.withIndex('barber_by_subservice', q =>
q.eq('subservice', args.subservice)
)
.collect()
const barbers = await Promise.all(barbersSubservices.map(doc => {
return ctx.db.get(doc.barberId)
})
const barberSubservices = await ctx.db
.query('subServicesByBarber')
.withIndex('barber_by_subservice', q =>
q.eq('subservice', args.subservice)
)
.collect()
const barbers = await Promise.all(barbersSubservices.map(doc => {
return ctx.db.get(doc.barberId)
})
swajp
swajpOP•16mo ago
Hi @erquhart thank you so much it works 😊

Did you find this page helpful?