ThaDafinser / ZfcDatagrid

New package available here (see website)
https://github.com/zfc-datagrid/zfc-datagrid/
MIT License
87 stars 57 forks source link

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

Closed ZeinEddin closed 10 years ago

ZeinEddin commented 10 years ago

I just got the latest updates of the ZfcDatagrid, and I am using it with Doctrin2, just selecting from one entity, and I got this error after the update:

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

In my action my code is simple as the following:

$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('p')->from('Permissions', 'p');

$dataGrid = $this->getServiceLocator()->get('zfcDatagrid');
$dataGrid->setDefaultItemsPerPage(50);
$dataGrid->setDataSource($qb);

$permId = new Column\Standard('id', 'p');
$permId->setIdentity();
$dataGrid->addColumn($permId);

$permissionCode = new Column\Standard('permissionCode', 'p');
$permissionCode->setLabel('Permission Code');
$permissionCode->setSortDefault(1, 'ASC');
$permissionCode->addStyle(new Style\Bold());
$dataGrid->addColumn($permissionCode);

$permissionDesc = new Column\Standard('permissionDesc', 'p');
$permissionDesc->setLabel('Permission Desc');
$dataGrid->addColumn($permissionDesc);

$dataGrid->execute();

return $dataGrid->getResponse();

I noticed that there has been some changes in Doctrine files, do I have to change anything in my code?

ZeinEddin commented 10 years ago

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

ThaDafinser commented 10 years ago

Yes there was a change. The problem is that my custom paginator implementation don't cover all "edge cases" of possible count queries (but only uses 2 queries). Until some updates ago, always my paginator implementation was used, but there was a wrong COUNT result in some cases.

I've implemented a detection method, there i check if it's save to use my pagination: https://github.com/ThaDafinser/ZfcDatagrid/blob/master/src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php#L60

Else the default doctrine one is used.

What type of database do you use?

This is the problem: I change the select part to the defined columns...which should not be done, befor the pagination. Your $qb is right, but i change it to the NOT WORKING

NOT working: 'SELECT c.id, c.number FROM Application\Entity\Course c' WORKING: 'SELECT c FROM Application\Entity\Course c'

I'll provide an update for this...

ZeinEddin commented 10 years ago

I am using Oracle

ThaDafinser commented 10 years ago

As far as i looked into the code, this is a nasty one.

Possible solution so far: Create a pagination wrapper for DoctrinePaginator, and use 2 $qb objects...one with the original select part for COUNT and one for the real select

ZeinEddin commented 10 years ago

The suggested solution is for the ZfcDatagrid itself not me, right? because in my code I am not using "count"... Can I help with anything to solve this issue? did you try anything?

ThaDafinser commented 10 years ago

@ZeinEddin i just tried now a quick solution....but that seems to be really hard...

Please try following: Always return true in following function: https://github.com/ThaDafinser/ZfcDatagrid/blob/master/src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php#L60

Does that work for you?

ThaDafinser commented 10 years ago

NOTE "why it's hard":

My idea was to let the select original (only for counting), so the paginator from doctrine "would" work. (Like in your link above provided as example).

But the problem is that filtering is done on the columns of the grid, so they have to be selected too...

ZeinEddin commented 10 years ago

I just updated the module on one of the projects (an Oracle project) and it seems working fine, I will try to test it on more projects (mySQL and Oralce) and see what will happen.

ThaDafinser commented 10 years ago

It works now for you like in the original patch.

Mostly the pagination will be correct. But when using complex queries with having, grouping....the count result will be wrong.

ZeinEddin commented 10 years ago

This is working fine now for Oracle... closing...