CakePHP可包含查找中的多个HABTM关联

CakePHP可包含查找中的多个HABTM关联,cakephp,find,associations,has-and-belongs-to-many,contain,Cakephp,Find,Associations,Has And Belongs To Many,Contain,我有两个模型之间的HABTM关联,但只能得到find返回一个级别。我可以与其他协会一起返回多个级别,但我想我一定是缺少了HABTM Controller/SchedulesController.php $this->Schedule->find('first', array( 'contain' => array( 'Association' => array( 'Schedule' ) ) )); public $actsAs =

我有两个模型之间的HABTM关联,但只能得到find返回一个级别。我可以与其他协会一起返回多个级别,但我想我一定是缺少了HABTM

Controller/SchedulesController.php

$this->Schedule->find('first', array(
  'contain' => array(
    'Association' => array(
      'Schedule'
    )
  )
));
public $actsAs = array('Containable');
public $hasAndBelongToMany = array(
  'Association'
);
public $actsAs = array('Containable');
public $hasAndBelongsToMany = array(
  'Schedule'
);
Model/Schedule.php

$this->Schedule->find('first', array(
  'contain' => array(
    'Association' => array(
      'Schedule'
    )
  )
));
public $actsAs = array('Containable');
public $hasAndBelongToMany = array(
  'Association'
);
public $actsAs = array('Containable');
public $hasAndBelongsToMany = array(
  'Schedule'
);
Model/Association.php

$this->Schedule->find('first', array(
  'contain' => array(
    'Association' => array(
      'Schedule'
    )
  )
));
public $actsAs = array('Containable');
public $hasAndBelongToMany = array(
  'Association'
);
public $actsAs = array('Containable');
public $hasAndBelongsToMany = array(
  'Schedule'
);
目前我只得到

array(
  'Schedule' => array(
     ...
  ),
  'Association' => array(
    (int) 0 => array(
      ...
    'AssociationsSchedule' => array(
      ...
    )
  )
)
…但是我希望Schedule->Association->Schedule

而contain()应该可以工作,另一个选项是在查找之前使用
递归
选项,如下所示:

$this->Schedule->recursive = 3; //2 might work, but I think you need 3 levels
$this->Schedule->find('first');

还值得一提的是,提出了一个类似的问题

为什么要两次使用相同的数据?