Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

DoctrineDataSource::getCount() failing because it does not reset LIMIT/OFFSET #1157

Open
FluffyDiscord opened this issue Dec 17, 2024 · 0 comments

Comments

@FluffyDiscord
Copy link

This function here needs to reset/remove LIMIT/OFFSET before it runs it's query.

This function
https://github.com/contributte/datagrid/blob/master/src/DataSource/DoctrineDataSource.php#L71

Should look like this:

public function getCount()
	{
		if ($this->usePaginator()) {
			return (new Paginator($this->getQuery()))->count();
		}
		$data_source = clone $this->data_source;
		$data_source->select(sprintf('COUNT(%s)', $this->checkAliases($this->primary_key)));
		$data_source->resetDQLPart('orderBy');
		
		// these two functions are needed
                $data_source->setFirstResult(null);
                $data_source->setMaxResults(null);

		return (int) $data_source->getQuery()->getSingleScalarResult();
	}

Without pagination reset you get exception:
Doctrine\ORM\NoResultException: No result was found for query although at least one row was expected

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

1 participant