Skip to content

Conversation

geeksilva97
Copy link

@geeksilva97 geeksilva97 commented Feb 24, 2025

Fixes #2693

@geeksilva97 geeksilva97 changed the title allow idColumn to be null Fix idColumn type Feb 24, 2025
@@ -1442,7 +1442,7 @@ declare namespace Objection {
QueryBuilder: typeof QueryBuilder;

tableName: string;
idColumn: string | string[];
idColumn: null | string | string[];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be last, not first? Also, it was suggested here to use never instead of null? What's more suitable?

#2693 (comment)

Copy link

@salisbury-espinosa salisbury-espinosa May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geeksilva97 @lehni
null - is not safe from the point of view of logic and types!
if you do not explicitly specify returning (for example returning(*)) then this will implicitly lead to the fact that it will try to use null (since the method will return null) and this will lead to an error at runtime!
see #2693 (comment)
that is, objection will compile an invalid SQL query!
therefore never is necessary - so that at the compilation stage (on the js side) there is an error, and an invalid SQL query does not sent to the database side!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does 'returning(*)' mean?

Copy link
Author

@geeksilva97 geeksilva97 May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this never thing when the doc explicitly says to use null

image

Maybe docs should be changed as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be last, not first? Also, it was suggested here to use never instead of null? What's more suitable?

#2693 (comment)

I don't think the order matters. Just let me know if you want me to change it

Copy link

@salisbury-espinosa salisbury-espinosa May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect typing of idColumn
3 participants