使用CakePhp 3.0.10
我想使用belongsTo选项创建一个through关系,但是我也需要设置joinTable选项,因为我的表有一个前缀
按照书中的例子,如果我写的话:
$this->belongsToMany('Courses', [
'through' => 'CourseMemberships',
'joinTable' => 'prefix_course_memberships',
]);我知道错误:
1146 Table 'course_memberships' doesn't exist这是一个bug,还是我可以强制cakephp使用我的表的方法?
发布于 2015-08-04 10:14:30
through选项取代joinTable选项,查看代码,这是预期的行为。
https://github.com/cakephp/.../src/ORM/Association/BelongsToMany.php#L173-L184
因此,如果您想在使用through时更改表名,只需在CourseMembershipsTable类中更改它,就像对任何其他表类一样。
public function initialize(array $config)
{
$this->table('prefix_course_memberships');
// ...
}https://stackoverflow.com/questions/31804798
复制相似问题