title: CakePHP counterCache joining irrelevant tables to update counter
body: <p>I have a User model and a Message model.</p>
  
  <p>The Message model is linked to the User model twice like this:</p>
  
  <pre><code>public $belongsTo = array(
      'UserSender' =&gt; array(
          'className' =&gt; 'User',
          'foreignKey' =&gt; 'sender_id',
          'counterCache' =&gt; array(
              'messages_sent_count' =&gt; array(
                  'is_deleted' =&gt; FALSE
              )
          )
      ),
      'UserRecipient' =&gt; array(
          'className' =&gt; 'User',
          'foreignKey' =&gt; 'recipient_id',
          'counterCache' =&gt; array(
              'messages_received_count' =&gt; array(
                  'is_deleted' =&gt; FALSE
              ),
              'messages_unread_count' =&gt; array(
                  'is_deleted' =&gt; FALSE,
                  'is_read' =&gt; FALSE
              )
          )
      ),
      'Operator' =&gt; array(
          'className' =&gt; 'Operator',
          'foreignKey' =&gt; 'operator_id'
      )
  );
  </code></pre>
  
  <p>Besides the User model, the Message model also $belongsTo the Operator model. The Operator model is irrelevant to the message count for the users, but its table is still being joined in the count query, as debug shows:</p>
  
  <pre><code>'query' =&gt; 'SELECT COUNT(*) AS `count` FROM `database`.`messages` AS  `Message` LEFT JOIN `database`.`operators` AS `Operator` ON (`Message`.`operator_id` = `Operator`.`id`) LEFT JOIN `database`.`users` AS `UserSender` ON (`Message`.`sender_id` = `UserSender`.`id`) LEFT JOIN `database`.`users` AS `UserRecipient` ON (`Message`.`recipient_id` = `UserRecipient`.`id`)  WHERE `Message`.`is_deleted` = '0' AND `Message`.`sender_id` = 389',
          'params' =&gt; array(),
          'affected' =&gt; (int) 1,
          'numRows' =&gt; (int) 1,
          'took' =&gt; (float) 394
  </code></pre>
  
  <p>For the sake of simplicity I've actually excluded one more model that the Message model $belongsTo, but the above query shows the problem.</p>
  
  <p>The counterCache function does a quite expensive query just to update the counter. Is there a way to maybe override or adjust the counterCache method to not join irrelevant tables in the query?</p>