2013-07-15 84 views
-1

如何在cakephp中實現此查詢?我無法從用戶表中獲取信息。加入cakephp 2.x

SELECT * FROM Manufacture LEFT JOIN Order ON Manufacture.order_id = Order.id 
LEFT JOIN User ON Order.user_id = User.id; 

製造:ID ORDER_ID

訂單:ID user_id說明

用戶:ID名稱

class Manufacture extends AppModel { 
    public $belongsTo = array(
     'Order' => array(
      'className' => 'Order', 
      'foreignKey' => 'order_id' 
     ) 
    ); 
} 

class Order extends AppModel { 
    public $belongsTo = array(
     'User' => array(
      'className' => 'User', 
      'foreignKey' => 'user_id' 
     )); 
} 

class User extends AppModel { 

} 

在控制器:

$this->Paginator->settings = array('limit' => 15); 
$this->set('entities', $this->Paginator->paginate('Manufacture')); 

回答