Welcome Guest, Not a member yet? Register   Sign In
Using Pagination with custom findAll()
#1

(This post was last modified: 04-27-2020, 03:02 PM by rmilecki.)

In my model I use custom findAll() as I need an extra join:
PHP Code:
public function findAll(int $limit 0int $offset 0)
{
    $this->select('documents.*');
    $this->select('authors.name AS author_name');
    $this->join('authors''authors.id = documents.author_id''left');

    return parent::findAll($limit$offset);


Then my controller is a simple code like this:
PHP Code:
$model = new DocumentsModel();
$model->like('authors.name''John');
$documents $model->findAll(); 

This worked great until I tried Pagination ($model->paginate()):
Code:
Unknown column 'authors.name' in 'where clause'

This problem is caused by Model::paginate() calling BaseBuilder::countAllResults() which doesn't use JOIN and so there is no authors.name column.

Can you suggest how can I rework my code to make things works, please?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB