Hi all, I have some issues with getting relations...
# help
m
Hi all, I have some issues with getting relations to work. I have multiple references set to my profiles table. However, this select is returning an error.
Copy code
js
const { data, error, status } = await supabase
        .from('rooms')
        .select('*, owner:profiles(nickname), opponent:profiles(nickname)');
    
hint    "By following the 'details' key, disambiguate the request by changing the url to /origin?select=relationship(*) or /origin?select=target!relationship(*)"
message    "More than one relationship was found for rooms and profiles"
details    [ {…}, {…} ]
0    Object { origin: "public.rooms", relationship: "rooms_opponent_fkey[opponent][id]", cardinality: "m2o", … }
origin    "public.rooms"
relationship    "rooms_opponent_fkey[opponent][id]"
cardinality    "m2o"
target    "public.profiles"
1    Object { origin: "public.rooms", relationship: "fk_profiles_rooms_opp[opponent][id]", cardinality: "m2o", … }
origin    "public.rooms"
relationship    "fk_profiles_rooms_opp[opponent][id]"
cardinality    "m2o"
target    "public.profiles"
How can I disambiguate these?
s
@User Try doing
Copy code
js
const { data, error, status } = await supabase
        .from('rooms')
        .select('*, owner:profiles!rooms_opponent_fkey(nickname), opponent:profiles!fk_profiles_rooms_opp(nickname)');
One thing, is it intended that
profiles
should have 2 Foreign Keys to
rooms
?
Both would enforce the same constraint, it seems.
Maybe you just have to delete one of the constraints to clear the error.
Like
Copy code
sql
ALTER TABLE rooms DROP CONSTRAINT fk_profiles_rooms_opp;
m
Hey @User, thanks, I will try that. It's referencing two different users on each column so I am not sure if one constraint would be enough.
s
I see. I've edited the JS snippet above.
m
thanks a lot 🙂