Skip to content
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

Improve Docs: "More than one relationship was found..." #745

Closed
AronBe opened this issue Feb 18, 2021 · 8 comments
Closed

Improve Docs: "More than one relationship was found..." #745

AronBe opened this issue Feb 18, 2021 · 8 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed

Comments

@AronBe
Copy link

AronBe commented Feb 18, 2021

It happened to me I deleted a column that had a foreign key constraint and for someone not working with databases, I didn't know it is a nono. It resulted in having multiple foreign keys after I added a new one to replace it.

Maybe we could either prevent it or warn the user that the foreign key should be first removed on the dropped column? Or remove the constraint with the column? Also, why can't have we have more foreign keys between 2 tables?

For those needing to resolve it and not having the column in the table editor, I have used sql editor to do it:

ALTER TABLE <table_name>
DROP CONSTRAINT <relationship_property_in_error_message>;
@AronBe AronBe added the enhancement New feature or request label Feb 18, 2021
@kiwicopple
Copy link
Member

Hey @AronBe - I'm not entirely sure if this is correct based on your description, but it may just be that PostgREST couldn't figure out which relationship to use.

Does this look right?

https://postgrest.org/en/v7.0.0/api.html#embedding-disambiguation

For doing resource embedding, PostgREST infers the relationship between two tables based on a foreign key between them. However, in cases where there’s more than one foreign key between two tables, it’s not possible to infer the relationship unambiguosly by just specifying the tables names.

@AronBe
Copy link
Author

AronBe commented Feb 18, 2021

@kiwicopple I have tested replacing table name with the foreign key name in my query and it worked, thank you! Documentation would be helpful, but I understand I should probably go to the source which is how actually postgrest works 👍

@kiwicopple
Copy link
Member

Agreed, we should add some examples to our docs. I'll leave this open and see if anyone wants to help out 👍

@kiwicopple kiwicopple added good first issue Good for newcomers help wanted Extra attention is needed documentation Improvements or additions to documentation and removed enhancement New feature or request labels Feb 22, 2021
@kiwicopple kiwicopple changed the title Error message: "More than one relationship was found..." Improve Docs: "More than one relationship was found..." Feb 22, 2021
@kiwicopple
Copy link
Member

Looks like we already have this example :)

https://supabase.io/docs/reference/javascript/select#query-the-same-foreign-table-multiple-times

@albertkimdev
Copy link

I created a view which caused Could not embed because more than one relationship was found for error.

I deleted the view but still get the same error.

@steve-chavez
Copy link
Member

@albertkimdev Can you share the full error message? With the hint and details fields.

@steve-chavez
Copy link
Member

@albertkimdev Also share the request

@albertkimdev
Copy link

@steve-chavez the issue was fixed by refreshing the cache after the view was deleted i think.

vonovak pushed a commit to vonovak/supabase that referenced this issue Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants