Skip to content

feat: Allow non-nullable id field when defaultModel is set - #3437

Merged
SandPod merged 15 commits into
serverpod:mainfrom
marcelomendoncasoares:feat-non-nullable-id-field
Apr 24, 2025
Merged

SandPod merged 15 commits into
serverpod:mainfrom
marcelomendoncasoares:feat-non-nullable-id-field

Conversation

@marcelomendoncasoares

@marcelomendoncasoares marcelomendoncasoares commented Apr 17, 2025 •

Copy link
Copy Markdown
Collaborator

This PR implements the possibility to declare non-nullable id fields, as specified on #3429. This is a follow-up from the #3416 PR.

To declare a field as non-nullable, just use the defaultModel keyword instead of the defaultPersist (only valid for UUID). It is still possible to declare nullable with defaultModel, in which case a hint will remind the user that it could be non-nullable to avoid unnecessary null checks.

Closes: #3429

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

No breaking changes, only the need to re-generate the models - as the TableRow.id field is no longer forcefully nullable. Instead, the nullability is declared in the generics of the class that extends it.

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice clean PR with structured commits.

The last commit had my questioning the migration system. why was it needed? And are we missing some migration steps in our SQL migration generator?

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

@SandPod
SandPod merged commit eba2814 into serverpod:main Apr 24, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 24, 2025
@marcelomendoncasoares
marcelomendoncasoares deleted the feat-non-nullable-id-field branch April 24, 2025 10:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use non-nullable id field when defaultModel is set.

2 participants