drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.44k stars 484 forks source link

[BUG]: Aggregated results from many-to-one relations doesn't return timestamp using postgres DB #2555

Open yudistiraashadi opened 4 days ago

yudistiraashadi commented 4 days ago

What version of drizzle-orm are you using?

0.31.2

What version of drizzle-kit are you using?

No response

Describe the Bug

Querying with db.query syntax, the included many-to-one relations data have all the timestamps columns be null. Below are the codes, my schemas, and the data in my databases hosted in Supabase. Notice at createdAt, updatedAt, and timestamp on absensiEvent are all null.

Query:

let latestAbsensiData = await db.query.absensi.findFirst({
    orderBy: [desc(absensi.tanggal)],
    with: {
      absensiEvent: true,
    },
    where: eq(absensi.userId, userId),
  });

Returned data: image

My Database (Postgres in Supabase, only showing what is needed. Check UUID on id, the same as the above screenshot): image

My schema: image

Expected behavior

The aggregated nested relations should have the timestamp columns not null. I tried with timestamp('columnName', { mode: 'string' }), and it actually gives the timestamp in ISO format. But that has another bug at #2282

Environment & setup

Framework: Next.js ver 14.2.3 Data fetcher: React's server actions called by TanStack Query ver 5.45.1