beerman
beerman4mo ago

unable to query relation with getOneFrom helper

import { query } from './_generated/server';
import { getOneFrom, getAll, getManyFrom, getManyVia } from 'convex-helpers/server/relationships';

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) => {
// Fetch related data here. For example:
const propertyType = await getOneFrom(
ctx.db,
'property_type_options',
'id',
property.property_type_id
);
const propertyLocation = await getOneFrom(
ctx.db,
'property_locations',
'id',
property.property_location_id
);

// Return the property with its related data
return {
...property,
propertyType,
propertyLocation
};
})
);
}
});
import { query } from './_generated/server';
import { getOneFrom, getAll, getManyFrom, getManyVia } from 'convex-helpers/server/relationships';

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) => {
// Fetch related data here. For example:
const propertyType = await getOneFrom(
ctx.db,
'property_type_options',
'id',
property.property_type_id
);
const propertyLocation = await getOneFrom(
ctx.db,
'property_locations',
'id',
property.property_location_id
);

// Return the property with its related data
return {
...property,
propertyType,
propertyLocation
};
})
);
}
});
3 Replies
beerman
beermanOP4mo ago
const properties = useQuery(api.properties.get);
$inspect(properties.data)
const properties = useQuery(api.properties.get);
$inspect(properties.data)
This gives me the following error. I also tried to use '_id' as the index, which also yields the same error.
Arguments for the rest parameter 'fieldArg' were not provided. src/convex/properties.ts:20:36 - error TS2554: Expected 5 arguments, but got 4. 20 const propertyLocation = await getOneFrom( ~~ node_modules/convex-helpers/server/relationships.d.ts:59:310 59 export declare function getOneFrom<DataModel extends GenericDataModel, TableName extends TablesWithLookups<DataModel>, IndexName extends UserIndexes<DataModel, TableName>>(db: GenericDatabaseReader<DataModel>, table: TableName, index: IndexName, value: TypeOfFirstIndexField<DataModel, TableName, IndexName>, ...fieldArg: FieldIfDoesntMatchIndex<DataModel, TableName, IndexName>): Promise<DocumentByName<DataModel, TableName> | null>; ~~~~~~~~~~~~~~~~~ Arguments for the rest parameter 'fieldArg' were not provided. Found 2 errors in the same file, starting at: src/convex/properties.ts:14
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!
beerman
beermanOP4mo ago
No description

Did you find this page helpful?