In my model I use custom findAll() as I need an extra join:
PHP Code:
public function findAll(int $limit = 0, int $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?