Обновите CakePHP 2 до 3 - ассоциации с использованием содержат - PullRequest
0 голосов
/ 15 июня 2019

Я модернизирую CakePHP 2 до CakePHP 3.

2 таблицы, мандаторы, информационные страницы.Первичные идентификаторы этих таблиц связываются с другой таблицей 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 не определена в Infopage.

Как это должно работать?

...