我如何 return 模型关联到相关模型?

How do I return models related to a related model?

我有3个模型。

WebcastTag 与 HABTMA 协会相关联。

WebcastHost 与 hasMany 关系相关联(Webcast 有许多 Host)。

当我执行 Tag->find 时,我得到 TagWebcast 模型,但是我想得到所有 3 个模型。我该怎么做?

来自文档

The recursive property defines how deep CakePHP should go to fetch associated model data via find(), and read() methods.

http://book.cakephp.org/2.0/en/models/model-attributes.html#recursive

如果您的查询使用的是 $this->webcast->find,那么您将获得所需的一切,除非您在查询之前不加入表格就无法搜索 'TAG'。如果您想在这种情况下搜索我推荐的 'TAG',那么您需要进入您的 Tag 模型并在那里创建关系。

标记 HABTM 网络广播

应该这样做。如果您没有获得主机,请在查询中尝试 'recursive' => 2。

$this->Tag->find('all');

$this->Tag->find('all', array('recursive' => 2));