title: Doctrine2 ORM - delete by FK without retrieving from DB
body: <p>I have two entities - UserAccounts (<code>user_accounts</code> table with <code>id</code> as PK) and BlacklistedUsers (<code>blacklisted_users</code> with <code>id</code> as PK and <code>user_account_id</code> as FK referencing to <code>user_accounts.id</code>). The challenge here is to delete the BlacklistedUsers entry by <code>user_accounts_id</code> column instead of the usual PK <code>id</code>. The important thing is that I do not want to load the entity from DB to delete it. I am also not willing to use DQL for such a simple query.</p>
  
  <p>I've been trying for a while already and keep getting different errors</p>
  
  <pre><code>$blacklist_ref = EntityManagerContainer::get()-&gt;getPartialReference(BlacklistedUsers::class, array("user_account_id" =&gt; $user_id));
  EntityManagerContainer::get()-&gt;remove($blacklist_ref);
  EntityManagerContainer::get()-&gt;flush();
  </code></pre>
  
  <blockquote>
    <p>{"errors":["Undefined index: user_account_id"]}</p>
  </blockquote>
  
  <pre><code>  $blacklist_ref = EntityManagerContainer::get()-&gt;getPartialReference(BlacklistedUsers::class, array("user_account" =&gt; $user_id));
    EntityManagerContainer::get()-&gt;remove($blacklist_ref);
    EntityManagerContainer::get()-&gt;flush();
  </code></pre>
  
  <blockquote>
    <p>{"errors":["Undefined index: user_account"]}</p>
  </blockquote>
  
  <pre><code>  $user_ref = EntityManagerContainer::get()-&gt;getReference(UserAccounts::class, $user_id);
    $blacklist_ref = EntityManagerContainer::get()-&gt;getPartialReference(BlacklistedUsers::class, array("user_account" =&gt; $user_ref));
    EntityManagerContainer::get()-&gt;remove($blacklist_ref);
    EntityManagerContainer::get()-&gt;flush();
  </code></pre>
  
  <blockquote>
    <p>{"errors":["Object of class DoctrineProxies\__CG__\Orm\Entity\UserAccounts could not be converted to string"]}</p>
  </blockquote>
  
  <pre><code>$user_ref = EntityManagerContainer::get()-&gt;getReference(UserAccounts::class, $user_id);
  $blacklist_ref = EntityManagerContainer::get()-&gt;getReference(BlacklistedUsers::class, array("user_account" =&gt; $user_ref));
  EntityManagerContainer::get()-&gt;remove($blacklist_ref);
  EntityManagerContainer::get()-&gt;flush();
  </code></pre>
  
  <blockquote>
    <p>{"errors":["The identifier id is missing for a query of Orm\Entity\BlacklistedUsers"]}</p>
  </blockquote>
  
  <p>Can Doctrine do such a simple thing through EntityManager? </p>
  
  <pre><code>"delete from blacklisted_users where user_account_id = {$id}"
  </code></pre>