What database are you using?

It might be an issue, but it's hard to tell:

* what database? (it looks like mysql quoting)

* do you think it's an issue that you're also using `c` just like the dbselect adapter as an alias? does it change the output if you change your alias? (Paginator uses c)

https://github.com/zendframework/zf2/blob/master/library/Zend/Paginator/Adapter/DbSelect.php#L115

-ralph



On 11/20/12 10:54 AM, Jean Rumeau wrote:
Hello, today i started addings records to a database to test the pagination
component.

The dbselect query im passing to the adapter as string is this:

SELECT `i`.*, `c`.`name` AS `categoryName`, CASE WHEN COUNT(bhi.id) > 0 THEN
1 ELSE 0 END AS `used` FROM `items` AS `i` INNER JOIN `categories` AS `c` ON
`c`.`id` = `i`.`category` LEFT JOIN `budget_has_item` AS `bhi` ON
`bhi`.`item` = `i`.`id` GROUP BY `i`.`id`

This query gets the items from a table 'items', its parent category name
from 'categories', and the column 'used' to see if this item has childs in a
table 'budget_has_items'.

This is working well to retrieve the rows, but the problem comes when i try
to paginate this results. I passed the select query as an object to the
adapter, and here the count fails because it adds the count field as another
field to the row.

In ZF1 the DbSelect adapter wrapped the query as a subselect, ie:

SELECT COUNT(1) as zend_paginator_row_count FROM (*SUBSELECT*)

But now the select generated is:

SELECT COUNT(1) AS `c`, `c`.`name` AS `categoryName`, CASE WHEN
COUNT(bhi.id) > 0 THEN 1 ELSE 0 END AS `used` FROM `items` AS `i` INNER JOIN
`categories` AS `c` ON `c`.`id` = `i`.`category` LEFT JOIN `budget_has_item`
AS `bhi` ON `bhi`.`item` = `i`.`id` GROUP BY `i`.`id`


What i want to know if this is an issue with the adapter or im executing an
invalid query. If i wrap the above query to make it look like the ZF1 one,
it works well.

Thanks.



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/ZF2-Paginator-DbSelect-not-counting-rows-as-expected-tp4658186.html
Sent from the Zend Framework mailing list archive at Nabble.com.



--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to