title: CakePHP 2.x : Cascade delete with softdelete do not work
body: <p>I use softdelete Behaviour of <a href="https://github.com/CakeDC/utils/tree/2.0-tests" rel="nofollow">Utils Plugin</a> for CakePHP 2.x</p>
  
  <p>I have following 4 tables </p>
  
  <ol>
  <li>customers  </li>
  <li>customer_addresses</li>
  <li>customer_contacts</li>
  <li>customer_reports</li>
  </ol>
  
  <p>And consider following its relationship with each other,</p>
  
  <p><strong>1. for customers</strong></p>
  
  <p>Customer hasMany CustomerAddress</p>
  
  <p>Customer hasMany CustomerContact</p>
  
  <p>Customer hasMany CustomerReport</p>
  
  <pre><code>public $hasMany = array(
      'CustomerAddress' =&gt; array(
          'className' =&gt; 'CustomerAddress',
          'foreignKey' =&gt; 'customer_id',
          'dependent' =&gt; true,
          ),
      'CustomerContact' =&gt; array(
          'className' =&gt; 'CustomerContact',
          'foreignKey' =&gt; 'customer_id',
          'dependent' =&gt; true,
          ),
      'CustomerReport' =&gt; array(
          'className' =&gt; 'CustomerReport',
          'foreignKey' =&gt; 'customer_id',
          'dependent' =&gt; true,
          )
  );
  </code></pre>
  
  <p><strong>2. for customer_addresses</strong></p>
  
  <p>CustomerAddress belongsTo Customer</p>
  
  <p>CustomerAddress belongsTo State</p>
  
  <p>CustomerAddress hasOne CustomerContact</p>
  
  <p>CustomerAddress hasOne CustomerReport</p>
  
  <pre><code>public $belongsTo = array(
      'Customer' =&gt; array(
          'className' =&gt; 'Customer',
          'foreignKey' =&gt; 'customer_id',
          'dependent' =&gt; false,
          ),
      'State' =&gt; array(
          'className' =&gt; 'State',
          'foreignKey' =&gt; 'state_id',
          )
  );
  public $hasOne = array(
      'CustomerContact' =&gt; array(
          'className' =&gt; 'CustomerContact',
          'foreignKey' =&gt; 'customer_address_id',
          'dependent' =&gt; true,
          ),
      'CustomerReport' =&gt; array(
          'className' =&gt; 'CustomerReport',
          'foreignKey' =&gt; 'customer_address_id',
          'dependent' =&gt; true,
          )
  );
  </code></pre>
  
  <p><strong>3. for customer_contacts</strong></p>
  
  <p>CustomerContact belongsTo Customer</p>
  
  <p>CustomerContact belongsTo CustomerAddress</p>
  
  <pre><code>public $belongsTo = array(
      'Customer' =&gt; array(
          'className' =&gt; 'Customer',
          'foreignKey' =&gt; 'customer_id',
          'dependent' =&gt; false,
          ),
      'CustomerAddress' =&gt; array(
          'className' =&gt; 'CustomerAddress',
          'foreignKey' =&gt; 'customer_address_id',
          'dependent' =&gt; true,
          )
  );
  </code></pre>
  
  <p><strong>4. for customer_reports</strong></p>
  
  <p>CustomerReport  belongsTo  Customer</p>
  
  <p>CustomerReport  belongsTo  CustomerAddress</p>
  
  <pre><code>public $belongsTo = array(
      'Customer' =&gt; array(
          'className' =&gt; 'Customer',
          'foreignKey' =&gt; 'customer_id',
          'dependent' =&gt; false,
          ),
      'CustomerAddress' =&gt; array(
          'className' =&gt; 'CustomerAddress',
          'foreignKey' =&gt; 'customer_address_id',
          'dependent' =&gt; true,
          )
  
  );
  </code></pre>
  
  <p>I have put below code in bootstrap.</p>
  
  <pre><code>CakePlugin::load('Utils');
  </code></pre>
  
  <p>I have also added below actAs in all above model</p>
  
  <pre><code>public $actsAs = array('Containable','Utils.SoftDelete');
  </code></pre>
  
  <p>I have already put below code in my appModel.</p>
  
  <pre><code>// for softdelete, checking exist id
  public function exists($id = null) {
      if ($this-&gt;Behaviors-&gt;attached('SoftDelete')) {
          return $this-&gt;existsAndNotDeleted($id);
      } else {
          return parent::exists($id);
      }
  }
  // for softdelete, overrite delete method
  public function delete($id = null, $cascade = true) {
      $result = parent::delete($id, $cascade);
      if ($result === false &amp;&amp; $this-&gt;Behaviors-&gt;enabled('SoftDelete')) {
         return $this-&gt;field('deleted', array('deleted' =&gt; 1));
      }
      return $result;
  }
  </code></pre>
  
  <p><strong>When I try to cascade delete with out soft delete ( means simple cascade delete ) , it works fine.
  But My problem is that.
  When I use softdelete behaviour of <a href="https://github.com/CakeDC/utils/tree/2.0-tests" rel="nofollow">Utils plugin</a> , Cascade delete does not work.</strong></p>
  
  <p>I have tried to delete record using below code</p>
  
  <pre><code>if ($this-&gt;CustomerAddress-&gt;delete()) {
          $this-&gt;Session-&gt;setFlash(__('CustomerAddress deleted'));
          $this-&gt;redirect($this-&gt;referer());
      }
  </code></pre>
  
  <p><strong>SQL log</strong></p>
  
  <pre><code>array(
  'log' =&gt; array(
      (int) 0 =&gt; array(
          'query' =&gt; 'SELECT COUNT(*) AS `count` FROM `lewie`.`customer_addresses` AS `CustomerAddress` LEFT JOIN `lewie`.`customers` AS `Customer` ON (`CustomerAddress`.`customer_id` = `Customer`.`id`) LEFT JOIN `lewie`.`states` AS `State` ON (`CustomerAddress`.`state_id` = `State`.`id`) LEFT JOIN `lewie`.`customer_contacts` AS `CustomerContact` ON (`CustomerContact`.`customer_address_id` = `CustomerAddress`.`id`) LEFT JOIN `lewie`.`customer_reports` AS `CustomerReport` ON (`CustomerReport`.`customer_address_id` = `CustomerAddress`.`id`)  WHERE `CustomerAddress`.`id` = 43 AND `CustomerAddress`.`deleted` = '0'',
          'params' =&gt; array(),
          'affected' =&gt; (int) 1,
          'numRows' =&gt; (int) 1,
          'took' =&gt; (float) 0
      ),
      (int) 1 =&gt; array(
          'query' =&gt; 'SELECT COUNT(*) AS `count` FROM `lewie`.`customer_addresses` AS `CustomerAddress` LEFT JOIN `lewie`.`customers` AS `Customer` ON (`CustomerAddress`.`customer_id` = `Customer`.`id`) LEFT JOIN `lewie`.`states` AS `State` ON (`CustomerAddress`.`state_id` = `State`.`id`) LEFT JOIN `lewie`.`customer_contacts` AS `CustomerContact` ON (`CustomerContact`.`customer_address_id` = `CustomerAddress`.`id` AND `CustomerContact`.`deleted` = '0') LEFT JOIN `lewie`.`customer_reports` AS `CustomerReport` ON (`CustomerReport`.`customer_address_id` = `CustomerAddress`.`id` AND `CustomerReport`.`deleted` = '0')  WHERE `CustomerAddress`.`id` = 43 AND `CustomerAddress`.`deleted` = '0'',
          'params' =&gt; array(),
          'affected' =&gt; (int) 1,
          'numRows' =&gt; (int) 1,
          'took' =&gt; (float) 1
      ),
      (int) 2 =&gt; array(
          'query' =&gt; 'SELECT COUNT(*) AS `count` FROM `lewie`.`customer_addresses` AS `CustomerAddress` LEFT JOIN `lewie`.`customers` AS `Customer` ON (`CustomerAddress`.`customer_id` = `Customer`.`id`) LEFT JOIN `lewie`.`states` AS `State` ON (`CustomerAddress`.`state_id` = `State`.`id`) LEFT JOIN `lewie`.`customer_contacts` AS `CustomerContact` ON (`CustomerContact`.`customer_address_id` = `CustomerAddress`.`id` AND `CustomerContact`.`deleted` = '0') LEFT JOIN `lewie`.`customer_reports` AS `CustomerReport` ON (`CustomerReport`.`customer_address_id` = `CustomerAddress`.`id` AND `CustomerReport`.`deleted` = '0')  WHERE `CustomerAddress`.`id` = 43 AND `CustomerAddress`.`deleted` = '0'',
          'params' =&gt; array(),
          'affected' =&gt; (int) 1,
          'numRows' =&gt; (int) 1,
          'took' =&gt; (float) 0
      ),
      (int) 3 =&gt; array(
          'query' =&gt; 'UPDATE `lewie`.`customer_addresses` SET `deleted` = '1', `deleted_date` = '2014-05-27 10:46:43', `modified` = '2014-05-27 10:46:43'  WHERE `lewie`.`customer_addresses`.`id` = '43'',
          'params' =&gt; array(),
          'affected' =&gt; (int) 1,
          'numRows' =&gt; (int) 1,
          'took' =&gt; (float) 0
      ),
      (int) 4 =&gt; array(
          'query' =&gt; 'SELECT `CustomerAddress`.`deleted` FROM `lewie`.`customer_addresses` AS `CustomerAddress`   WHERE `deleted` = '1'    LIMIT 1',
          'params' =&gt; array(),
          'affected' =&gt; (int) 1,
          'numRows' =&gt; (int) 1,
          'took' =&gt; (float) 0
      )
  ),
  'count' =&gt; (int) 5,
  'time' =&gt; (float) 1)
  </code></pre>
  
  <p>How can I resolve this problem?</p>