title: creating virtual fields on the fly in CakePHP
body: <p>I wish to create virtual fields on the fly.</p>
  
  <p>My Order &amp; Order Details are like...</p>
  
  <pre><code>//Order Model
  class Order extends AppModel {
      public $name = 'Order';
      public $actsAs = array('Containable');
      public $hasMany = array(
          'OrderDetail' =&gt; array(
              'className' =&gt; 'OrderDetail',
              'foreignKey' =&gt; 'order_id',
              'dependent' =&gt; true
          ),
      );
  }
  
  //OrderDetail Model
    class OrderDetail extends AppModel {
      public $name = 'OrderDetail';
      public $actsAs = array('Containable');
      public $belongsTo = array(
          'Order' =&gt; array(
              'className' =&gt; 'Order',
              'foreignKey' =&gt; 'order_id',
              'dependent' =&gt; true
          ),
      );
  }
  </code></pre>
  
  <p>The model relation is like this. I am creating virtual fields on the fly so that I can count number of items and their cost in order pagination. I know the weird way of <code>requestAction</code>. Is their any way other I can perform my task.</p>
  
  <p>My tried code is</p>
  
  <pre><code>        $this-&gt;Order-&gt;virtualFields['totalCost'] = 0;
          $this-&gt;Order-&gt;virtualFields['totalItem'] = 0;
          $fields = array('Order.id', 'Order.order_key', 'Order.delivery_date','COUNT(`OrderDetail`.`order_id`) AS `Order__totalItem`', 'SUM(`OrderDetail`.`cost`) AS `Order__totalCost`');         
  
          $this-&gt;paginate['Order'] = array("fields"=&gt;$fields, 'conditions' =&gt; array("AND" =&gt; array($condition, "Order.status" =&gt; 3)), 'limit' =&gt; '50', 'order' =&gt; array('Order.id' =&gt; 'DESC'));
  </code></pre>
  
  <p>It ends me with the mysql not found column <code>Unknown column 'OrderDetail.order_id' in 'field list'</code>. I haven't put recursive or bind my model to find something else. Why this error is generated ? How can I achieve my aim.</p>