0

模型箱

public $hasMany = array('Ticket' => array(
        'className' => 'Ticket',
        'order' => 'Ticket.created DESC',
        'foreign_key' => 'box_id'
    ));  

模型票

public $belongsTo = 'Box';

在 BoxesController 我从盒子表中获取数据

$this->set('boxes', $this->Box->find('all'));

此函数从表 Box 和表 Ticket 中获取所有数据。如何只从一个表中获取数据,而不连接其他表?

4

1 回答 1

2
$this->Box->recursive = -1;
$this->set('boxes', $this->Box->find('all'));

或者

$this->Box->unbindModel(
        array('hasMany' => array('Ticket'))
   );
$this->set('boxes', $this->Box->find('all'));

更多关于递归

于 2013-08-02T14:58:38.023 回答