在 cakephp 3 beta 中使用 HasMany 关系分页 table

Paginate table with HasMany relation in cakephp 3 beta

我有包含 (group_id,member_id,city_id) 字段的广告 table。这是我的 GroupsController->view 方法。

public function view($id = null) {
    $group = $this->Groups->get($id);
    $this->paginate = ['conditions'=>['group_id'=>$id] , 'contain'=>['Members', 'Cities']];
    $advertisements = $this->paginate($this->Groups->Advertisements);
    $this->set(compact('group' , 'advertisements'));
}

除了真实结果之外,它还会生成此警告。

Warning (4096): Argument 1 passed to Cake\Controller\Component\PaginatorComponent::validateSort() must be an instance of Cake\ORM\Table, instance of Cake\ORM\Association\HasMany given, called in D:\xampp\htdocs\project\vendor\cakephp\cakephp\src\Controller\Component\PaginatorComponent.php on line 153 and defined [CORE\src\Controller\Component\PaginatorComponent.php, line 301]

怎么了?

magic property getters return \Cake\ORM\Association instances, if you need the actual \Cake\ORM\Table object, use Association::target().

$this->Groups->Advertisements->target()