New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order on a foreign table #971
Comments
You can workaround for this issue using foreign table reference same as in select method const { data, error } = await supabase
.from('countries')
.select(`
name,
cities (
name
)
`)
.order('cities(name)', { ascending: false }) |
When I try this I get the following Postgres error: {
code: 'PGRST100',
details: `unexpected '(' expecting letter, digit, "-", "->>", "->", delimiter (.), "," or end of input`,
hint: null,
message: '"failed to parse order (product_category(name).desc)" (line 1, column 17)'
} This is my specific query: const {data, error} = await supabase.from("product").select("id, product_category(name)").order("product_category(name)", { ascending: false }) Any idea how to work around this? |
This requires PostgREST v11. |
I had to change the structure of my relations a bit, so now I have a many-to-many relationship between my products and my product categories. I created a separate table fot this called I was hoping that I could still order by the const {data, error} = await supabase
.from("product")
.select("id, product_to_product_category(product_category(name, primary))")
.order("name", { ascending: false, referencedTable: product_to_product_category.product_category }) Is there any way to make this work? |
Hi, I have been unable to get FWIW @KajSzy 's workaround is working for me. I wanted to get clarity on this open issue. Is it related to the functionality of ordering with |
Facing the same issue. Using const {data, error} = await supabase
.from('haikus')
.select(
'id, content, created_at, profiles(id, username, avatar_path), likes!inner()'
)
.eq('likes.profile_id', userId)
.order('created_at', { referencedTable: 'likes', ascending: false });
Tried doing this, but I got an error: const {data, error} = await supabase
.from('haikus')
.select(
'id, content, created_at, profiles(id, username, avatar_path), likes!inner()'
)
.eq('likes.profile_id', userId)
.order('likes(created_at)', { ascending: false }); {
code: 'PGRST118';
details: "'haikus' and 'likes' do not form a many-to-one or one-to-one relationship";
hint: null;
message: "A related order on 'likes' is not possible";
} |
Bug report
Describe the bug
Hey guys, I am not an expert around here but hear me out :)
Based on docs here on how to order the query result
on a referenced table
.First issue is that, maybe the docs is outdated but, this options key is called
foreignTable
in thesupabase-js
package2.38.3
.Secondly, when i add foreignTable option to order the foreign table that comes with the query, in Typescript, I am given the columns of the base table of the query (
countries
in this example) as autocomplete. Though, I can still use the desired column name as the order value and TS will not yell about it.Expected behavior
If I want to order the foreign table and add that option key, TS should recognize that so I should be able to use the columns of that table to order. The inferred type is still the columns of the base table.
System information
The text was updated successfully, but these errors were encountered: