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

feat: support nullable embedded entities #10829

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

test137E29B
Copy link

Support nullable embedded fields such that embedded documents in MongoDB can correctly be returned as null for a subdocument that is explicitly nullable.

Closes: #3913

Description of change

This change adds to the ColumnEmbeddedOptions the nullable field, thus allowing subdocuments in MongoDB to be null explicitly. This ensures they're returned correctly from the database in the case a null is set. This is useful when a developer has a required key that can be set to null - currently the key is not returned at all.

I saw this in #3913 though this was reverted as it previously changed all nested fields to null, which caused some problems I imagine for people. This method of implementing this change should not cause problems or any breaking changes and is entirely optional.

I have locally tested this with MongoDB, but not a SQL provider.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

Support nullable embedded fields such that embedded documents in MongoDB can correctly be returned as null for a subdocument that is explicitly nullable.

Closes: typeorm#3913
This commit formats the new changes to ensure they follow the standards for contributing to the project.
This commit adds the documentation required for usage of the nullable embedded entities, plus the example code.
@test137E29B
Copy link
Author

test137E29B commented Apr 14, 2024

Would love if someone could add support for this in SQL providers, since my changes don't seem to have worked. I can't imagine it's not too hard.

Alternatively, I can just add a note that this will only work for MongoDB.

Open to opinions on this 😃

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.

Cannot set embedded entity to null
1 participant