How to handle 2 ForeignKeys to the same Table? #115
-
Hey, constraint runs_pkey primary key (id),
constraint runs_runner_id_fkey foreign key (runner_id) references runners (id),
constraint runs_verifier_id_fkey foreign key (verifier_id) references runners (id) on update cascade on delete set default Class Run [Table("runs")]
public class Run : BaseModel
{
[PrimaryKey("id", false)]
public string Id { get; set; } = string.Empty;
[Reference(typeof(Runner))]
public Runner? Runner { get; set; }
[Reference(typeof(Runner))]
public Runner? Verifier { get; set; } Select Statement var result = await _client.From<Run>()
.Select("*")
.Filter("games.name", Operator.Equals, gName)
.Filter("categories.name", Operator.Equals, cName)
.Limit(100)
.Get(cancellationToken);
return result.Models; Error Message from Supabase API {
"type": "https://tools.ietf.org/html/rfc7231#section-6.6.1",
"title": "An error occurred while processing your request.",
"status": 500,
"detail": "{\"code\":\"PGRST201\",\"details\":[{\"cardinality\":\"many-to-one\",\"embedding\":\"runs with runners\",\"relationship\":\"runs_runner_id_fkey using runs(runner_id) and runners(id)\"},{\"cardinality\":\"many-to-one\",\"embedding\":\"runs with runners\",\"relationship\":\"runs_verifier_id_fkey using runs(verifier_id) and runners(id)\"}],\"hint\":\"Try changing 'runners' to one of the following: 'runners!runs_runner_id_fkey', 'runners!runs_verifier_id_fkey'. Find the desired relationship in the 'details' key.\",\"message\":\"Could not embed because more than one relationship was found for 'runs' and 'runners'\"}"
} Is this even possible or what am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Answered by
acupofjose
Oct 9, 2023
Replies: 1 comment 3 replies
-
Try adjusting your select to: .Select("*, runners!runs_runner_id_fkey:Runner, runners!runs_verifier_id_fkey:Verifier`) And see if that works. If so, we should probably add a parameter to the |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Cegoco11 it was useful indeed! Thanks for diving into that.
@Morethna - This should be supported in postgrest-csharp v3.2.8 - waiting on the nuget publish to complete.
You can see how relationships are defined here:
https://github.com/supabase-community/postgrest-csharp/blob/99af1c74715f0fc3738e85ffbda9abef583dfd14/PostgrestTests/Models/ForeignKeyTestModel.cs#L1-L18