Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Problem with Doctrine pagination #76

Open
cbichis opened this issue Sep 3, 2015 · 7 comments
Open

Problem with Doctrine pagination #76

cbichis opened this issue Sep 3, 2015 · 7 comments

Comments

@cbichis
Copy link

cbichis commented Sep 3, 2015

Hi,

It seems we are affected by the same problem as

http://www.doctrine-project.org/jira/browse/DDC-1927

By example for this source:

protected function getSource() {

    $queryBuilder = $this->getObjectManager()->createQueryBuilder();

    $queryBuilder
            ->select('e.id id')
            ->from('Application\Entity\Package', 'e')
            ->join('e.user', 'u');

    return $queryBuilder;
}

Is returned an error:

Not all identifier properties can be found in the ResultSetMapping: id

I am trying to select multiple fields from each table, of course, I reduced the sample to minimum to see the problem...

@W33k3nd
Copy link

W33k3nd commented Sep 3, 2015

I 've got the same problem. I think this problem happens, because Doctrine Paginator missed the join identifier.

$queryBuilder
        ->select('e', 'u')
        ->from('Application\Entity\Package', 'e')
        ->join('e.user', 'u');

@cbichis
Copy link
Author

cbichis commented Sep 3, 2015

Is that working for you ?

I don't think I can mass select the u entity, I need to only fetch from second table a CONCAT(u.first_name, ' ', u.last_name) staff_name

@W33k3nd
Copy link

W33k3nd commented Sep 3, 2015

No!
My other problem was, i used two id annotations in one of my tables (Id-> filename, Id -> group). Doctrine Paginator can't handle this yet.
http://www.doctrine-project.org/jira/browse/DDC-2213

Also i solved my problem to add an auto increment id and canceled the other id's as normal values and add an unique index with filename and group.

@W33k3nd
Copy link

W33k3nd commented Sep 3, 2015

Perhaps help this
doctrine/DoctrineORMModule#66

@cbichis
Copy link
Author

cbichis commented Sep 3, 2015

I found a workaround.

ZfTable\Source\DoctrineQueryBuilder getPaginator() should be modified as below:

    public function getPaginator()
    {
        if (!$this->paginator) {


            $this->order();

            $doctrinePaginator = new ORMPaginator($this->query);
            $doctrinePaginator->setUseOutputWalkers(false);

             $adapter = new DoctrineAdapter($doctrinePaginator);
             $this->paginator = new Paginator($adapter);
             $this->initPaginator();

        }
        return $this->paginator;
    }

@cbichis
Copy link
Author

cbichis commented Sep 3, 2015

I think we should have a out of the box way to disable the OutputWalker.

@aNorthernSoul
Copy link

aNorthernSoul commented Mar 30, 2017

I ran into the issue of the OutputWalkers for optimization and did the following.

In my table classes that extend AbstractTable I added the following function:

`
use Application\Helpers\Extensions\ExtendZfTableDoctrineQueryBuilder;

class MyTable extends AbstractTable
{

...

public function setExtendedDoctrineSource($source)
{
    if ($source instanceof QueryBuilder) {
        $source = new ExtendZfTableDoctrineQueryBuilder($source);
    } else {
        throw new \Exception('This type of source is undefined');
    }

    $source->setTable($this);
    $this->source = $source;
    return $this;
}

}
`

Then I have the following as ExtendZfTableDoctrineQueryBuilder which allows me to configure Doctrine as I wanted.

`
namespace Application\Helpers\Extensions;

use ZfTable\Source\DoctrineQueryBuilder;
use ZfTable\Source\AbstractSource;
use Zend\Paginator\Paginator;
use DoctrineORMModule\Paginator\Adapter\DoctrinePaginator as DoctrineAdapter;
use Doctrine\ORM\Tools\Pagination\Paginator as ORMPaginator;

class ExtendZfTableDoctrineQueryBuilder extends DoctrineQueryBuilder
{

/**
 *
 * @var \Doctrine\ORM\QueryBuilder
 */
protected $query;

/**
 *
 * @var  \Zend\Paginator\Paginator
 */
protected $paginator;

/**
 *
 * @param \Doctrine\ORM\QueryBuilder $query
 */
public function __construct($query)
{
    $this->query = $query;
}

/**
 *
 * @return \Zend\Paginator\Paginator
 */
public function getPaginator()
{
    if (!$this->paginator) {


        $this->order();

         $ormPaginator = new ORMPaginator($this->query);
         $ormPaginator->setUseOutputWalkers(false);
         $adapter = new DoctrineAdapter($ormPaginator);
         $this->paginator = new Paginator($adapter);
         $this->initPaginator();

    }
    return $this->paginator;
}



protected function order()
{
    $column = $this->getParamAdapter()->getColumn();
    $order = $this->getParamAdapter()->getOrder();

    if (!$column) {
        return;
    }

    $header = $this->getTable()->getHeader($column);
    $tableAlias = ($header) ? $header->getTableAlias() : 'q';

    if (false === strpos($tableAlias, '.')) {
        $tableAlias = $tableAlias.'.'.$column;
    }

    $this->query->orderBy($tableAlias, $order);
}


public function getQuery()
{
    return $this->query;
}

}
`

Sorry, hopefully that is readable. I can't seem to keep my code within the code blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants