Pagination for Comments

In your first example, you’re passing a query in to paginate, which is overriding the limit with its own default. In the second case, you’re explicitly telling paginate what the limit should be. So:

$query = $this->Comments
    ->find()
    ->contain([‘Users’, ‘Users.Profiles’])
    ->where([‘article_id =’ => $id]);
$comments = $this->paginate($query, ['limit' => 5]);

should work as expected. (You can do it all without the $query variable; I separated it to make it clearer what is doing what.)