【发布时间】:2020-03-25 11:07:21
【问题描述】:
我在使用这个我必须管理的旧框架时遇到了一些问题。
我有这些表:
- 组 -> 有很多 -> 监控器
- 监视器 -> 有很多 -> [事件,区域]
- 监视器 -> HAS_AND_BELONGS_TO_MANY -> 组
对于 GROUP -> MONITOR 关系,Cake 创建了一个名为 GROUP_MONITOR 的连接表。
这是组模型上的 HasMany 配置:
'Monitor' => array(
'className' => 'Monitor',
'joinTable' => 'Groups_Monitors',
'foreignKey' => 'GroupId',
'associationForeignKey' => 'MonitorId',
问题 1:
我正在尝试检索具有所有相关监视器的所有组。我找到了允许深入关系的递归键:
$all_groups = $this->Group->find('all', array('recursive' => 1));
我收到了这个错误:
找不到列:1054 '字段列表'中的未知列 'Monitor.GroupId'"
Cake 似乎没有使用“Groups_Monitors”表,而是在 Monitor 表中搜索 groupId;
问题 2:
试图让 Groups 查询 Monitors,递归到 1 我正确地得到了所有组,但也得到了所有其他 Monitor 的 HasMany 关系。
$all_monitors = $this->Monitor->find('all',array("recursive" => 1));
是否可以在 find 中排除一些 HasMany 关系以减少数据量?
【问题讨论】: