vicious-gold
vicious-gold2y ago

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
Omer
Omer2y ago
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
vicious-gold
vicious-gold2y 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
Omer
Omer2y ago
Which data provider are you using?
fair-rose
fair-rose2y 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, });