【发布时间】:2014-06-24 16:31:37
【问题描述】:
我需要一个治疗师有很多孩子的协会,反之亦然。
我有 3 张桌子:
治疗师 孩子们 儿童治疗师
你可以在下面看到关联:
治疗师.php
public $hasAndBelongsToMany = array('Child' =>
array(
'className' => 'Children',
'joinTable' => 'children_therapists',
'foreignKey' => 'therapist_id',
'associationForeignKey' => 'child_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => 'Child.last_name',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'with' => ''
)
);
在 Child.php 模型中,我尝试了以下代码:
public $useTable = 'children';
但这没有用。
当我对它进行编码时,我收到以下错误:
缺少数据库表
错误:在数据源默认值中找不到模型 Child 的子表。
非常感谢任何帮助。
谢谢, 格雷格
【问题讨论】:
-
问题出在 Children 模型,而不是 Child 模型。 Cake 正在寻找儿童桌(通常称为
childrens)。您需要在 Children 模型中设置$useTable = 'children';。 -
或者,如果 Children 实际上不是模型,则需要将关联中的
className => Children更改为 Child。