Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
swerky opened this issue Jan 14, 2025 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@swerky
Copy link

swerky commented Jan 14, 2025

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))
@swerky swerky added the bug Something isn't working label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant