drizzle-team / drizzle-team/drizzle-orm

[BUG]: Nested partial select type inconsistency between simple query and pgView

Open
#4,401 0 comments 0 reactions 0 assignees View on GitHub
bug priority qb/crud
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] 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.41.0

### What version of `drizzle-kit` are you using?

0.30.6

### Other packages

_No response_

### Describe the Bug

### What is the undesired behavior?

In this minimal [ts-playground ](https://www.typescriptlang.org/play/?noErrorTruncation=true#code/JYWwDg9gTgLgBAbzgEysAXugNgUzgXzgDMoIQ4AiVDbHAWmhAHpIBnGAcyh1boCtWFANwAoUJFiI4YDgBUAhgCNcAGmkcAasBwB3NQDd5UAMYALIwWKlyVNJlwMozGXWPQcwseGjwkOAI5qHDgwCso4AMIQWACuIAB2rGry8ciWJGSU1Pb0jJ4ibonwMEq4AIJwALzqYbgAFBQl4QD68hRqCCJwcMDIAFxwhibmUA29FACUAHRgaCBGAJ4A0jgLdRMqIvgTogUQRXBNuABCVTWlOA1HOM2K7YhdPf2DRmZGY8iTM3OLK2sbWx2Ij2B2QijO2VodQQhHkrDgKQWQJB7Dg-ghikeU1YOFwxhg0Me3UUA2CoQuUViCVYdWuxwB3W2WIyIFpFzKEyxuCIMAAUhBgPE2eFjmoAsLylNemprmUpcgJsjCqj9NodGcZFpdA1VbovnC6usqgA+B7dbgwGJQeJo0TbXbK+BQM7yHTyYDwfyiR1wKAAJhdbo9KEU2NxOHx6ymLLqup0QKAA). We see r and r2 do not have the same resulting type. Both use nested select object syntax, one directly on a query, and the other on a pgView. The simple query returns the whole b table object as nullable, but not the id field, whereas the view makes the id field nullable, but not the b table object

### What is the desired result?

Both should have the same type. As stated in the [docs](https://orm.drizzle.team/docs/joins):

> To avoid plethora of nullable fields when joining tables with lots of columns we can utilise our nested select object syntax, our smart type inference will make whole object nullable instead of making all table fields nullable!

So both should make the b object table nullable, not the id field

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.