Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
By default, the
HalModelSerializer
classifies all nestedBaseSerializer
instances as embedded nested objects. In reality, the REST representation need not align 1:1 with the database representation so it should be possible to override this behavior.For example, I'm supporting a 3rd party data specification (HL7v3) which has a 1:many relationship between Patient and ID (i.e. each patient can have multiple IDs). For indexing reasons, this means that IDs need to be in their own table, but they're not really intended as embedded objects (e.g. they aren't independently linkable).
This PR creates a
HalPromoteEmbeddedMixin
that can be added to a nested serializer to indicate that it should be stored at the top level of the representation (and not_embedded
).P.S. I really wanted to add a check to
__init__
to make sure theMeta.list_serializer_class
also usesHalPromoteEmbeddedMixin
. If you don't add it in both places, themany=True
serializer won't pick up the behavior. The problem is (1) I don't want to raise an exception because you don't have to mess with it if you never usemany
and (2) we don't importlogging
anywhere in the package so I didn't have a standard pattern to follow.