Cakephp 3.4 - setMatching() 和 getMatching() 的用法

Cakephp 3.4 - Usage of setMatching() and getMatching()

我已经升级到 CakePHP 3.4,我正在检查 3.4 弃用列表,迁移指南说 getMatching() 必须在 setMatching() 之后调用以保持旧行为 我很困惑,找不到关于 setMatching() 和 getMatching() 函数示例的任何文档。我应该如何或在哪里声明 setMatching()。谁能告诉我如何使用 setMatching 和 getMatching 重写以下代码:

TableRegistry::get('Students')->find()
        ->distinct([ 'Students.id'])
        ->matching('Studentclassrooms.Classrooms',
              function ($q) use ( $classid ){
                   return $q->where([ 'Classrooms.id' => $classid ]);
              });
        ->enableAutoFields(true);

当我尝试以下操作时,出现错误

Unknown method "setMatching”

TableRegistry::get('Students')->find()
        ->distinct([ 'Students.id'])
        ->setMatching('Studentclassrooms.Classrooms',
              function ($q) use ( $classid ){
                    return $q->where([ 'Classrooms.id' => $classid ]);
              })
        ->getMatching()
        ->enableAutoFields(true);

仔细查看迁移指南(目前已关闭,似乎是托管商的问题),\Cake\ORM\Query::matching() 并未弃用,而是 \Cake\ORM\EagerLoader::matching()(内部使用在 \Cake\ORM\Query::matching()) 中,没有 \Cake\ORM\Query::setMatching()/getMatching() 方法,但是 \Cake\ORM\EagerLoader::setMatching()/getMatching().

必须在 setMatching() 之后调用 getMatching() 是因为与 matching('Alias') 不同,后者将 return 包含数组,setMatching('Alias') 将设置匹配东西,而是 return $this。因此,为了检索准备好的容器数组,您必须在之后调用 getMatching()

长话短说,您的示例中没有任何内容需要重写。