We’d prefer not to use pagination so the new unsetPagination() was welcomed. But we found that the limit (whatever default_per_page is) is still applied to the number of records when setCustomQuery() isn’t used. I’m not sure if this is a misunderstanding from our side? The documentation says “This is useful when you want to display all records without pagination, or when working with custom queries that return a limited dataset.” – the first part of that sentence, “when you want to display all records”, applies to us and the second part is an “or” not an “and”, so shouldn’t it work without setCustomQuery() too?
I guess I found a crude workaround using setModel() to a custom model. Basically rewrite getList() without setting the limit or offset in the custom model.
<?php
namespace App\Models;
use GroceryCrud\Core\Profiler\FileProfiler;
use Laminas\Db\Adapter\Adapter;
use Laminas\Db\Sql\Predicate;
use Laminas\Db\Sql\Sql;
use Laminas\Db\Sql\Select;
use Laminas\Db\Sql\Expression;
use Laminas\Db\Sql\Predicate\PredicateSet;
use Laminas\Db\Sql\TableIdentifier;
use Laminas\Db\Sql\Where;
use Laminas\Db\Adapter\Profiler\ProfilerInterface;
use GroceryCrud\Core\Model;
use GroceryCrud\Core\Model\ModelInterface;
use GroceryCrud\Core\Helpers\ArrayHelper;
use GroceryCrud\Core\Model\ModelFieldType;
class AppBaseModel extends Model {
public function getList()
{
$sql = new Sql($this->adapter);
$select = $sql->select();
$select->columns($this->getColumns());
// disable limit and offset
// $select->limit($this->limit);
// $select->offset(($this->limit * ($this->page - 1)));
$select->from($this->getTableNameWithSchema($this->tableName));
$order_by = $this->orderBy;
$sorting = $this->sorting;
if ($order_by !== null) {
$sortingString = ($sorting === null) ? '' : ' ' . $sorting;
if ($this->isFieldWithRelation($order_by)) {
$relationField = $this->_relation_1_n[$order_by];
$shortNameForRelationTable = $this->getShortName($relationField->tableName, $relationField->fieldName);
if (is_array($relationField->titleField)) {
$orderingFields = [];
foreach ($relationField->titleField as $titleField) {
$orderingFields[] = $shortNameForRelationTable . '.' . $titleField . $sortingString;
}
$select->order($orderingFields);
} else {
$order_by = $shortNameForRelationTable . '.' . $relationField->titleField;
$select->order($order_by . $sortingString);
}
} else {
if (is_array($order_by)) {
$select->order($order_by);
} else {
$select->order($order_by . $sortingString);
}
}
} else {
$select = $this->defaultOrdering($select);
}
if (!empty($this->_filters)) {
$select = $this->filtering($select, PredicateSet::OP_AND);
}
if (!empty($this->_filters_or)) {
$select = $this->filtering($select, PredicateSet::OP_OR);
}
$select = $this->joinStatements($select);
$select = $this->extraJoinStatements($select);
$select = $this->whereStatements($select);
$select = $this->extraWhereStatements($select);
$results = $this->getResultsFromSelect($select, $sql);
$resultsIds = $this->_getOnlyPrimaryKeyValues($results);
$results = $this->concatRelationalData($results, $resultsIds);
return $results;
}
}
This is a new function and to be honest, I haven’t thought about it very well. The main reason was the serve the setCustomQuery but didn’t thought that people want to actually remove the pagination completely (which make sense).
I will try to have this working as expected at the next version.