<?php

namespace Oro\Bundle\DataGridBundle\Datasource\Orm;

use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;

use Oro\Bundle\DataGridBundle\Datasource\ResultRecord;
use Oro\Bundle\BatchBundle\ORM\Query\BufferedQueryResultIterator;

/**
 * Iterates query result with elements of ResultRecord type
 */
class IterableResult extends BufferedQueryResultIterator implements IterableResultInterface
{
    /**
     * @var QueryBuilder|Query
     */
    private $source;

    /**
     * Current ResultRecord, populated from query result row
     *
     * @var mixed
     */
    private $current = null;

    /**
     * Constructor
     *
     * @param QueryBuilder|Query $source
     */
    public function __construct($source)
    {
        parent::__construct($source);
        $this->source = $source;
    }

    /**
     * {@inheritDoc}
     */
    public function current()
    {
        return $this->current;
    }

    /**
     * {@inheritDoc}
     */
    public function next()
    {
        parent::next();

        $current = parent::current();
        $this->current = $current === null
            ? null
            : new ResultRecord($current);
    }

    /**
     * {@inheritDoc}
     */
    public function getSource()
    {
        return $this->source;
    }
}

<?php

namespace Oro\Bundle\DataGridBundle\Datasource\Orm;

use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;

use Oro\Bundle\DataGridBundle\Datasource\ResultRecord;
use Oro\Bundle\BatchBundle\ORM\Query\BufferedQueryResultIterator;

/**
 * Iterates query result with elements of ResultRecord type
 */
class IterableResult extends BufferedQueryResultIterator implements IterableResultInterface
{
    /**
     * @var QueryBuilder|Query
     */
    private $source;

    /**
     * Current ResultRecord, populated from query result row
     *
     * @var mixed
     */
    private $current = null;

    /**
     * Constructor
     *
     * @param QueryBuilder|Query $source
     * @param null|bool $useCountWalker
     */
    public function __construct($source, $useCountWalker = null)
    {
        parent::__construct($source, $useCountWalker);
        $this->source = $source;
    }

    /**
     * {@inheritDoc}
     */
    public function current()
    {
        return $this->current;
    }

    /**
     * {@inheritDoc}
     */
    public function next()
    {
        parent::next();

        $current = parent::current();
        $this->current = $current === null
            ? null
            : new ResultRecord($current);
    }

    /**
     * {@inheritDoc}
     */
    public function getSource()
    {
        return $this->source;
    }
}

Set whether to use count walker for iterator count
Set whether to use count walker for iterator count

Can get the following error:

```
Cannot count query that uses a HAVING clause. Use the output walkers for pagination
```

This can happen when attempting to iterate over a query containing a 'HAVING' clause. Allowing the user to set that a count walker shouldn't be used to get a count, the error won't happen.

Seen when performing a bulk action on a datagrid with a filter enabled that has the `filter_by_having` property set to `true`.