title: Whats the best way to override object deletion in Sonata Admin?
body: <p>I already have a custom CRUD controller. So do I just need to override <code>Controller::deleteAction()</code> and <code>Controller::batchDeleteAction()</code> from <code>Sonata\AdminBundle\Controller</code> ?</p>
  
  <p>Or is it preferable / better practice to override the Admin class's delete methods?</p>
  
  <p>My desired behaviour is that I want to update a record with an archived flag rather than delete the entity.</p>
  
  <p>The docs are <a href="http://sonata-project.org/bundles/admin/master/doc/reference/action_delete.html" rel="nofollow">incomplete</a> on this subject</p>
  
  <p><strong>Update</strong></p>
  
  <p>The following code in my Entity's Repository class iterates over a query object as per the <code>batchDelete</code> method in the <code>ModelManager</code></p>
  
  <pre><code>public function batchArchive($class, ProxyQuery $queryProxy)
      {
  
          $queryProxy-&gt;select('DISTINCT '.$queryProxy-&gt;getRootAlias());
  
          try {
              $entityManager = $this-&gt;getEntityManager();
  
              $batchSize = 20;
              $i = 0;
  
              foreach ($queryProxy-&gt;getQuery()-&gt;iterate() as $pos =&gt; $object) {
  
                  $this-&gt;archiveMyEntity($object); //???
                  if (($i % $batchSize)  == 0) {
                      $entityManager-&gt;flush();
                      $entityManager-&gt;clear();
                  }
                  ++$i;
              }
  
          } catch (\PDOException $e) {
              throw new ModelManagerException('', 0, $e);
          } catch (DBALException $e) {
              throw new ModelManagerException('', 0, $e);
          }
      }
  </code></pre>
  
  <p>The problem I have is that the object my archiveMyEntity() method expects is an Entity object not a query object. </p>