How to query all elements with foreign key
Hello to all,
my first post here! So i have a maybe noob question but how can i query some element that has a foreign_key related to the current edit object?
Ex:
i'm on the edit page of a Category and i want to be able to display all properties related to this Category that lives in a table named "category_properties"
Thanks!
4 Replies
Hey @.fiorex 👋,
Welcome, we are glad to see you! 🍻
You can use "useOne" data hook ⚡️
https://refine.dev/docs/api-reference/core/hooks/data/useOne/
useOne | refine
useOne data hook from refine is a modified version of react-query's useQuery for retrieving single items from a resource
correct-apricot•2y ago
Thank @Omer but i think i didn't explain well what i want to do.
in the edit page of a Category i want to take all rows from another table (named CategoryProperties) that ha category_id === Category.id
Which data provider are you using?
exotic-emerald•2y ago
You can override the table it looks for by passing in resource in the hook
const categoryQueryResult = useList<ICategory>({
resource: "category_properties",
id: 1,
});