© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
3 replies
chrismasters

Why does this simple foreign key one-to-many relationship give Typescript errors ?

If I have simple relationship where each playlist includes a list of tracks...
CREATE TABLE public.playlists (
    id bigint generated by default as identity primary key,
    track_id bigint references public.tracks NOT NULL
);
CREATE TABLE public.tracks (
    id bigint generated by default as identity primary key,
    title text NOT NULL,
    artist_name text
);
CREATE TABLE public.playlists (
    id bigint generated by default as identity primary key,
    track_id bigint references public.tracks NOT NULL
);
CREATE TABLE public.tracks (
    id bigint generated by default as identity primary key,
    title text NOT NULL,
    artist_name text
);

And then access this with a query like this...
const { data } = await supabase
  .from('playlists')
  .select(`
    id,
    tracks (
      title,
      artist_name
    )
  `)
const { data } = await supabase
  .from('playlists')
  .select(`
    id,
    tracks (
      title,
      artist_name
    )
  `)

I'd imagined that
tracks.title
tracks.title
could only be either a
string
string
or
null
null
type so I could use
tracks?.title
tracks?.title
to make Typescript happy.

But my typescript is giving errors if I use either
tracks.title
tracks.title
or
tracks?.title
tracks?.title


Property 'title' does not exist on type '({ title: string; } & { artist_name: string | null; }) | ({ title: string; } & { artist_name: string | null; })[]'.
Property 'title' does not exist on type '({ title: string; } & { artist_name: string | null; })[]'.
Property 'title' does not exist on type '({ title: string; } & { artist_name: string | null; }) | ({ title: string; } & { artist_name: string | null; })[]'.
Property 'title' does not exist on type '({ title: string; } & { artist_name: string | null; })[]'.


What am I missing?

Also, semantically, shouldn't this relationship name be better changed to
track
track
from
tracks
tracks
as it is singular?

Thanks!
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Foreign key relationship isn't one to one
SupabaseSSupabase / help-and-questions
3mo ago
RLS One to many relationship
SupabaseSSupabase / help-and-questions
4y ago
how to have an array of foreign keys (one to many relationship)?
SupabaseSSupabase / help-and-questions
4y ago
inner join without foreign key relationship
SupabaseSSupabase / help-and-questions
3y ago