Skip to content

Can findAll function in modeling data accept 3rd parameter reset #3024

Description

@engrsandeep

Sometime, we need to generate just of count all results after getting limited records for pagination. Is it possible to add 3rd parameter in find all function in modeling data and update it like below. code which is working fine, or provide a function to set reset function at model level, so it can be done on/off as required.

/**
* Works with the current Query Builder instance to return
* all results, while optionally limiting them.
*
* @PARAM integer $limit
* @PARAM integer $offset
* @PARAM boolean $reset
*
* @return array
*/
public function findAll(int $limit = 0, int $offset = 0,$reset = true)
{
$builder = $this->builder();

	if ($this->tempUseSoftDeletes === true)
	{
		$builder->where($this->table . '.' . $this->deletedField, null);
	}

	$row = $builder->get($limit, $offset,$reset);

	$row = $row->getResult($this->tempReturnType);

	$eventData = $this->trigger('afterFind', ['data' => $row, 'limit' => $limit, 'offset' => $offset]);

	$this->tempReturnType     = $this->returnType;
	$this->tempUseSoftDeletes = $this->useSoftDeletes;

	return $eventData['data'];
}

Many thanks for making Codeigniter 4 in good shape.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions