Deleting an entity does not delete indexed data
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3586039. -->
Reported by: [mxr576](https://www.drupal.org/user/315522)
>>>
<p>[Tracker]<br>
<strong>Update Summary: </strong>[One-line status update for stakeholders]<br>
<strong>Check-in Date: </strong>MM/DD/YYYY<br>
<strong>Blocked by: </strong>[#XXXXXX] (New issues on new lines)<br>
<strong>Additional Collaborators: </strong> @username1, @username2<br>
<em>Metadata is used by the <a href="https://www.drupalstarforge.ai/" title="AI Tracker">AI Tracker.</a> Docs and additional fields <a href="https://www.drupalstarforge.ai/ai-dashboard/docs" title="AI Issue Tracker Documentation">here</a>.</em><br>
[/Tracker]</p>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>When an entity which gets indexed via AI search gets deleted then its data does not get deleted from related database tables in Postgres.</p>
<p>The root cause is exactly the same as in <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-8"><a href="https://www.drupal.org/project/ai_provider_amazeeio/issues/3579511" title="Status: Needs review">#3579511: VDB: Clearing index data does not delete data/table for multivalue filterable attributes</a></span>:</p>
<blockquote><p>1. Ensure that the <code>deleteFromCollection() </code>actually deletes using the <code>id</code> field rather than <code>drupal_entity_id</code> since that is what it should be filtering against.
</p></blockquote>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>* Fix the problematic function implementation to delete entity related data from all tables in Posgres.<br>
* Would be nice if we could provide an update hook that would remove stale that, if that is even possible... (or we can only suggest clear indexed data and re-index).</p>
<h3 id="summary-remaining-tasks">Target date or deadline</h3>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3 id="summary-ai-usage">AI usage (if applicable)</h3>
<p>[ ] AI Assisted Issue<br>
This issue was generated with AI assistance, but was reviewed and refined by the creator.</p>
<p>[ ] AI Assisted Code<br>
This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.</p>
<p>[ ] AI Generated Code<br>
This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.</p>
<p>[ ] Vibe Coded<br>
This code was generated by an AI and has only been functionally tested.</p>
> Related issue: [Issue #3579511](https://www.drupal.org/node/3579511)
issue