EntityResourceBase::createCollectionDataFromEntities assumes all the entities would be of same entity type and leading to data loss.
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3565859. --> Reported by: [amangrover90](https://www.drupal.org/user/3602433) Related to !23 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>EntityResourceBase::createCollectionDataFromEntities assumes all the entities would be of same entity type and leading to data loss.<br> 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. </p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <ol> <li>Install this module along with jsonapi_search_api module.</li> <li> Setup a search index that tracks multiple entity types e.g. nodes and users/comments etc. </li><li> Create 2 nodes and 2 comments, at least one node and user entity should have same id. </li><li> Try accessing the json api route of the index. </li><li> See that the data for node is getting overridden by the user entity(or vice versa, whichever comes later.) </li></ol> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>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.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <h3 id="summary-ui-changes">User interface changes</h3> <p>NA</p> <h3 id="summary-api-changes">API changes</h3> <h3 id="summary-data-model-changes">Data model changes</h3>
issue