Problem/Motivation

EntityResourceBase::createCollectionDataFromEntities assumes all the entities would be of same entity type and leading to data loss.
If there's an entity-oriented JSON:API Resource which tries to render entities of multiple entity types then EntityResourceBase::createCollectionDataFromEntities overrides the data for one entity with other if the entity ids match.

Steps to reproduce

  1. Install this module along with jsonapi_search_api module.
  2. Setup a search index that tracks multiple entity types e.g. nodes and users/comments etc.
  3. Create 2 nodes and 2 comments, at least one node and user entity should have same id.
  4. Try accessing the json api route of the index.
  5. See that the data for node is getting overridden by the user entity(or vice versa, whichever comes later.)

Proposed resolution

EntityResourceBase::createCollectionDataFromEntities should either use entity uuids to track the entity resource data or use "{entity_type}:{entity_id}" as the identifier. Currently it's using {entity_id} which causes the override.

Remaining tasks

User interface changes

NA

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

amangrover90 created an issue. See original summary.

ankitv18 made their first commit to this issue’s fork.

mglaman’s picture

Status: Active » Fixed

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • mglaman committed 73a097bc on 8.x-1.x authored by ankitv18
    feat: #3565859 EntityResourceBase::createCollectionDataFromEntities...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.