supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
964 stars 128 forks source link

Typings on query results don't match actual returned values #469

Closed kiya-abdulahi closed 4 months ago

kiya-abdulahi commented 10 months ago

Bug report

Describe the bug

I have a relationship between tables that looks something like this:

CREATE TABLE "event" (
  "id" serial PRIMARY KEY,
  "slug" VARCHAR NOT NULL,
   .....a few more columns,
);

CREATE TABLE "product" (
  "id" serial PRIMARY KEY,
  "event_id" int UNIQUE NOT NULL,
  .....a few more columns,
);

CREATE INDEX ON "product" ("event_id");
ALTER TABLE "product" ADD FOREIGN KEY ("event_id") REFERENCES "event" ("id") ON DELETE CASCADE;

I then query my event table by slug and join on product as such:

const { data: event, error } = await db
      .from('event')
      .select('*, product(*)')
      .eq('slug', slug)
      .single()

Now my event with a single product should be returned. When I try to target my event doing the following:

const product = event?.product

Product typing comes back as an array. But when I log the product to my console, i see its not an array but indeed a single product object. This is causing my typings to be incorrect.

Is there something im missing in regards to joins that explains this behavior? Or perhaps my tables are incorrect?

Expected behavior

Expect product to not be an array but an object.

Screenshot

The screenshot shows that when hovering over event?.product, it indicates it's an array. But when I log event?.product, you can see in my terminal that it's not an array but its an object.

image

System information

cdimitroulas commented 8 months ago

We're also experiencing this same issue.

Seems this other issue is also reporting the same problem: https://github.com/supabase/postgrest-js/issues/477

FranciscoHS19 commented 7 months ago

Also experiencing this issue. Any news on the bugfix?

farischt commented 4 months ago

I believe this one can be closed as of reading this: https://github.com/supabase/postgrest-js/issues/477