Problem/Motivation
There are a few existing issues (added as related) dealing with core/json:api module's assumption that entity references are, basically, always "core" entity references which can only target a single entity type. The denormalization performed in the top-level JSON:API normalizer does what amounts to early denormalization of this data and deprives field normalizers (or Extras field enhancers) sufficient information about the reference to accomodate for other entity type targets. E.g., Dynamic Entity Reference needs to set entity_type
in addition to target_id
.
Interestingly, we are dangerously close to actually supporting this, in so far as the target entity type is identifiable by its public json:api name, which is how these entities actually pass initial validation and are loaded up to get their target IDs.
You can post DER data by specifying the target_type
in meta
, however this is unnecessary as it effectively duplicates the type member of the relationship identifier object and requires the client to know about this drupalism (and potentially expose your internals.) See #2888553: Handle denormalizing meta payload in relationships where this pattern was introduced.
Note that there is #3027430: [PP-2] Dynamic Entity Reference normalization support and others which address the normalization/querying side, but AFAICT simple reporting of DER field data "works", and there may be some quirks with querying (particularly as it releates to included data and filtering by relationships) but there are no open issues for the create/update denormalization side of the coin.
Steps to reproduce
Try to post just a relationship with type
and id
to a DER field.
Proposed resolution
Load up what I'm referring to as the "early denormalized" value array for entity references with the entity type; this should be a no-op for the core ER field but will provide DER with what it needs (and any other field doing something similar.)