You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use non-nullable id field when defaultModel is set. #3429
When defaultModel is used to define the id column it will always be initialized regardless of if it is provided or not. Therefore, there is no need to have this field nullable in the model.
Proposal
Emit a warning or force a change during code generation or validation if defaultModel: true is used and the id field is nullable. This encourages users to make the id field non-nullable, even though it's currently technically allowed to be nullable.
Use Case
Accessing a non-nullable field through a nullable getter just creates unnecessary null checks in the code.
Alternatives
N/A
Additional context
This helps guide developers toward safer usage patterns.
I can take this on. Just don't know if we need the warning, as it does not exist today for the usage with defaultModel in regular fields. I think we need to allow non-nullable - which will probably be everyone's first choice -, but I would leave the developer free to declare it as nullable with no warning, just as for other fields. Because someone could use it intentionally to force a obj.id = null after creation in some use case.
Activity
marcelomendoncasoares commentedon Apr 16, 2025
I can take this on. Just don't know if we need the warning, as it does not exist today for the usage with
defaultModelin regular fields. I think we need to allow non-nullable - which will probably be everyone's first choice -, but I would leave the developer free to declare it as nullable with no warning, just as for other fields. Because someone could use it intentionally to force aobj.id = nullafter creation in some use case.SandPod commentedon Apr 16, 2025
True, maybe we just add a simple hint?