Add support for custom relationships to ReferenceAttribute

Open
#328 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp, postgresql
Domain
api, databases

Research direction

Open Postgrest/Attributes/ReferenceAttribute.cs at the ColumnName/ForeignKey logic around lines 183-194. Trace how ReferenceAttribute derives the embedded field name, then verify that a ColumnName without ForeignKey is used for both select construction and returned-JSON parsing while existing ForeignKey behavior remains unchanged.

Written by the indexing model from the issue text.

Description

area: postgrest feature

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 https://github.com/supabase-community/postgrest-csharp/blob/726dbd8d3af7e85cc11bbdad66ca3750809240c4/Postgrest/Attributes/ReferenceAttribute.cs#L183-L194

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

Dominant language
C#
Stars
701
Forks
106
Avg merge
16h 35m
Merged PRs (30d)
45

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from supabase/supabase-csharp

All issues in supabase/supabase-csharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.