Feature request
PostgREST supports defining custom relationships between tables.
See https://docs.postgrest.org/en/stable/references/api/resource_embedding.html#computed-relationships
The field name in the select queries and in the returned JSON is determined by the name of each function. The name may match the table name that's being returned, but it doesn't have to.
I have a situation where we have multiple different relationships between the same two tables. As a result, we have defined multiple computed relationship functions in PostgreSQL. Each function/relationships has a different field name. I need to provide this custom field name to the ReferenceAttribute for each embedded relationship field in the associated C# model so that the C# client uses the correct field name when querying for the embedded relationship and parsing the returned JSON.
ReferenceAttribute already provides a ColumnName property that could be used. However, that property is only used to determine the field name if the ForeignKey property is also set, which isn't applicable in this case.
See
|
if (!string.IsNullOrEmpty(refAttr.ForeignKey)) |
|
{ |
|
Columns.Add(UseInnerJoin |
|
? $"{refAttr.ColumnName}:{refAttr.ForeignKey}!inner({string.Join(",", refAttr.Columns.ToArray())})" |
|
: $"{refAttr.ColumnName}:{refAttr.ForeignKey}({string.Join(",", refAttr.Columns.ToArray())})"); |
|
} |
|
else |
|
{ |
|
Columns.Add(UseInnerJoin |
|
? $"{refAttr.TableName}!inner({string.Join(",", refAttr.Columns.ToArray())})" |
|
: $"{refAttr.TableName}({string.Join(",", refAttr.Columns.ToArray())})"); |
|
} |
Describe the solution you'd like
A simple solution is to update ReferenceAttribute so that, if ColumnName is set but ForeignKey is not, then ColumnName is used instead of TableName.
System information
Version of Supabase.Postgrest: 4.1.0
Feature request
PostgREST supports defining custom relationships between tables.
See https://docs.postgrest.org/en/stable/references/api/resource_embedding.html#computed-relationships
The field name in the select queries and in the returned JSON is determined by the name of each function. The name may match the table name that's being returned, but it doesn't have to.
I have a situation where we have multiple different relationships between the same two tables. As a result, we have defined multiple computed relationship functions in PostgreSQL. Each function/relationships has a different field name. I need to provide this custom field name to the
ReferenceAttributefor each embedded relationship field in the associated C# model so that the C# client uses the correct field name when querying for the embedded relationship and parsing the returned JSON.ReferenceAttributealready provides aColumnNameproperty that could be used. However, that property is only used to determine the field name if theForeignKeyproperty is also set, which isn't applicable in this case.See
postgrest-csharp/Postgrest/Attributes/ReferenceAttribute.cs
Lines 183 to 194 in 726dbd8
Describe the solution you'd like
A simple solution is to update
ReferenceAttributeso that, ifColumnNameis set butForeignKeyis not, thenColumnNameis used instead ofTableName.System information
Version of Supabase.Postgrest: 4.1.0