CakePHP 3.x paginate关联模型(belongsToMany)

时间:2015-05-29 09:36:15

标签: cakephp-3.0

我有一个模型交易愿望与城市模型(belongsToMany)相关联,最终我获取一个与ID相关的城市与该城市相关的交易,在DealsTable中我有获取功能:

public function findByCity($city){

    return $this->Cities->get($city , ['contain' => ['Deals']]);
}

并且在DealsController中我想要对与所获取的城市相关联的交易进行分页,我在CakePHP 3书中找不到解决方案。

1 个答案:

答案 0 :(得分:1)

据我所知,不可能对关联进行分页。我会做这样的事情:

$city = $this->Cities->get($city);
$deals = $this->paginate($this->Cities->Deals->findByCityId($city->id));

return ['city'=>$city, 'deals'=>$deals];