deep-jade
deep-jade8mo ago

Change id column name for useOne to anything other than "id"

This seems like such an easy question to answer, but after hours of searching through the docs and already asked questions on Discord I give up and post this here. I'm using useOne to get data from a resource like this
const { data: rawData, isLoading: isLoading, isError: isError } = useOne({
resource: "users",
id: user_id,
});
const { data: rawData, isLoading: isLoading, isError: isError } = useOne({
resource: "users",
id: user_id,
});
My issue is that the column containing the user id in table "users" is not called "id" in the database but "user_id". How can I make sure useOne uses "users.user_id" as column to check for the id and not "users.id". Right now I'm receiving the error
"message": "column users.id does not exist"
"message": "column users.id does not exist"
because of course the column users.id doesn't exist
3 Replies
kapa.ai
kapa.ai8mo ago
Hi @fuss132. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- You can use the meta property to match the column name of the primary key in your data table to the column name you have assigned. In your case, you can pass the id parameter to the meta property to change the column name to user_id. Here's how you can do it:
const { data: rawData, isLoading: isLoading, isError: isError } = useOne({
resource: "users",
id: user_id,
meta: {
idColumnName: "user_id",
},
});
const { data: rawData, isLoading: isLoading, isError: isError } = useOne({
resource: "users",
id: user_id,
meta: {
idColumnName: "user_id",
},
});
Now, it will search for users in the user_id column of the data table instead of id column. For more information, you can refer to the documentation (https://refine.dev/docs/packages/documentation/data-providers/supabase/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai8mo ago
<@178960777435283456> kapa.ai is still learning and improving, please let us know how it did by reacting below
deep-jade
deep-jade8mo ago
Yes! That's it. Many thanks to the AI 😄