我正在将cakephp 2升级到cakephp3。
2个表强制项,信息页。 这些表的主要ID与另一个表mandators_infopages关联为mandator_id和infopage_id
class InfopageTable extends Table
{
public function initialize(array $config)
{
$this->table('infopages');
$this->belongsToMany('Mandator', [
'className' => 'Mandator',
'joinTable' => 'mandators_infopages',
'foreignKey' => 'infopage_id',
'associationForeignKey' => 'mandator_id',
'unique' => true,
]);
}
}
class MandatorTable extends Table
{
public function initialize(array $config)
{
$this->table('mandators');
$this->belongsToMany('Infopage', [
'className' => 'Infopage',
'joinTable' => 'mandators_infopages',
'foreignKey' => 'mandator_id',
'associationForeignKey' => 'infopage_id',
'unique' => true,
]);
}
}
$this->paginate = ['contain' =>
['MandatorsInfopages']
];
$query = $this->Infopage->find('all')
->where($conditions)
->group('Infopage.id');
$data = $this->paginate($query)->toArray()
条件
Array
(
[OR] => Array
(
[Infopage.name LIKE ] => %%
[Infopage.content LIKE ] => %%
)
[AND] => Array
(
[MandatorsInfopages.mandator_id] => 12
)
)
提供错误:未在信息页上定义MandatorsInfopages关联。
它应该如何工作?