left join not properly hydrating results

tx
.select({
...getTableColumns(projects),
clients: { id: clients.id, name: clients.name },
})
.from(projects)
.leftJoin(clients, eq(clients.id, projects.clientId))
tx
.select({
...getTableColumns(projects),
clients: { id: clients.id, name: clients.name },
})
.from(projects)
.leftJoin(clients, eq(clients.id, projects.clientId))
The query this generates is correct:
select "projects"."id", "projects"."created_at", "projects"."updated_at", "projects"."organization_id", "projects"."name", "projects"."client_id", "clients"."id", "clients"."name" from "projects" left join "clients" on "clients"."id" = "projects"."client_id"
select "projects"."id", "projects"."created_at", "projects"."updated_at", "projects"."organization_id", "projects"."name", "projects"."client_id", "clients"."id", "clients"."name" from "projects" left join "clients" on "clients"."id" = "projects"."client_id"
And running this query also returns the clients name, as expected. But the resulting object says clients is null, whereas I am expecting an object with the id and name values set. Why is this not hydrating?
1 Reply
RWOverdijk
RWOverdijkOP3w ago
It looks like a bug. I think it's the same. But there is a PR: https://github.com/drizzle-team/drizzle-orm/pull/1825
GitHub
Fix nested partial select which returns null on left join if first ...
Fixes [BUG]: Nested Partial Select returns null on left join if first column value is null #1603 /claim #1603 The issue was with the nullifyMap in the mapResultRow method, which was not updating ...

Did you find this page helpful?