Skip to content

[BUG]: Nested object null when first field is null even if the other field aren't null #3948

@swerky

Description

@swerky

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.3

What version of drizzle-kit are you using?

0.28.1

Other packages

No response

Describe the Bug

When using the nested object syntax with a leftJoin, I found a bug where the order of the properties defined if the all nested object is null. It looks like it only look the first field to define if the nested object will be defined.

My address table:

export const addressTable = pgTable("address", {
	latitude: customDecimal().notNull(),
	longitude: customDecimal().notNull(),
	name: text(),
}, (table) => [
	index().on(table.latitude, table.longitude),
]);

In this query, if my addressName is null, the all object is null even if the latitude and longitude is set.

db.select({
  id: sessionTable.id,
  inPersonDetails: {
    addressName: addressTable.name,
    addressLatitude: addressTable.latitude,
    addressLongitude: addressTable.longitude,
  }
})
.from(sessionTable)
.leftJoin(addressTable, eq(addressTable.id, sessionTable.addressId))

The address is not mandatory but in my test it was set.

But if I but the addressName at the end of the object, even if the addressName is null I still receive my inPersonDetails object with my latitude and longitude. (This is the behavior that is the more logical to me.

db.select({
  id: sessionTable.id,
  inPersonDetails: {
    addressLatitude: addressTable.latitude,
    addressLongitude: addressTable.longitude,
    addressName: addressTable.name,
  }
})
.from(sessionTable)
.leftJoin(addressTable, eq(addressTable.id, sessionTable.addressId))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions