JSON:API assumes entity reference field's main property must be the entity ID

Created on 23 September 2024, 7 months ago

Problem/Motivation

The core entity reference field does not document any requirement that the main property name on the field is the same as the value of the entity ID.

However, the code in jsonapi module assumes this is true in at least a couple places. This breaks subclasses of EntityReferenceItem that use the UUID (e.g. entity_reference_uuid module) or some other unique identifier (e.g. the revision ID) as the main property.

related:
#3050845: Includes using the `entity_reference_uuid` contrib module not working β†’
πŸ› Cannot use UUID as entity ID Needs work

Steps to reproduce

Using the entity_reference_uuid module, try to include related data for the reference filed, or try to send a PATCH request to the relationship URL

Proposed resolution

Since we are already loading the entity, we can simply use/assign the "entity" property on the reference field instead of trying to guess the mapping of entity ID to property name.

Remaining tasks

port contrib patch, update core patch

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

todo

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

jsonapi.module

Created by

πŸ‡ΊπŸ‡ΈUnited States pwolanin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024