beerman
beerman4mo ago

a little confused about getManyVia

Hey all, I have a table features which stores different feature options and joiner table property_features which connects the features to properties and has an additional details field for property specific information per feature. I'm trying to get all the property features (name, as well as the details), so I thought that getManyVia would be the best option to use, but I'm only getting the names but not the details. Have I misunderstood how this works? extract from schema
properties: defineTable({
...
})

features: defineTable({
name: v.string()
})
.index('by_name', ['name']),

property_features: defineTable({
feature_id: v.id('features'),
property_id: v.id('properties'),
details: v.optional(v.string())
})
.index('by_feature_id', ['feature_id'])
.index('by_property_id', ['property_id']),
properties: defineTable({
...
})

features: defineTable({
name: v.string()
})
.index('by_name', ['name']),

property_features: defineTable({
feature_id: v.id('features'),
property_id: v.id('properties'),
details: v.optional(v.string())
})
.index('by_feature_id', ['feature_id'])
.index('by_property_id', ['property_id']),
query
export const get = query({
args: {},
handler: async (ctx) => {
// Fetch all properties
const properties = await ctx.db.query('properties').collect();

// Fetch related data for each property
return await Promise.all(
properties.map(async (property) => {
const propertyFeatures = await getManyVia(
ctx.db,
'property_features',
'feature_id',
'by_property_id',
property._id
);

return {
propertyFeatures
};
})
);
}
});
export const get = query({
args: {},
handler: async (ctx) => {
// Fetch all properties
const properties = await ctx.db.query('properties').collect();

// Fetch related data for each property
return await Promise.all(
properties.map(async (property) => {
const propertyFeatures = await getManyVia(
ctx.db,
'property_features',
'feature_id',
'by_property_id',
property._id
);

return {
propertyFeatures
};
})
);
}
});
1 Reply
Convex Bot
Convex Bot4mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!

Did you find this page helpful?