Bug #62518
closedWrong result count
0%
Description
Code:
$result = $this->pageRepository->findByTagAndCategory($tag, $category); if($result->count() > 0) { // always returns the number of pages total }
If I echo the result count in my controller or in the view before processing the rows in a for-loop, the result count always returns the number of all entries in the db. The wrong result count can be "fixed" with a empty loop:
$result = $this->pageRepository->findByTagAndCategory($tag, $category); foreach($result as $row) { // empty for loop to adjust counting } if($result->count() > 0) { // always return the number of total results }
Updated by Stefan Froemken over 8 years ago
Hello Natalia,
I know such a problem, but only if you work with $query->statement in Repository. Can you confirm that or post the content of method findByTagAndCategory in this ticket?
Stefan
Updated by Natalia Postnikova over 8 years ago
Stefan Froemken wrote:
Hello Natalia,
I know such a problem, but only if you work with $query->statement in Repository. Can you confirm that or post the content of method findByTagAndCategory in this ticket?
Stefan
Hello Stefan,
yes, I can confirm that.
Updated by Stefan Froemken over 8 years ago
Hello Natalia,
you can't use count() on Statement-Objects. If you make use of $query->statement it is good to return result as array: $query->execute(TRUE).
Here is a full example of one of my extensions:
public function findPoisByCategories($categories) { $query = $this->createQuery(); $statement = new TYPO3\CMS\Core\Database\PreparedStatement('My SQL-Query statement', 'tx_maps2_domain_model_poicollection'); $query->statement($statement, array('tx_maps2_domain_model_poicollection')); return $query->execute(TRUE); }
Stefan
Updated by Wouter Wolters almost 8 years ago
- Status changed from New to Closed
Solution is given by Stefan. I therefore close the ticket.
If you think that this is the wrong decision or experience this issue again, then please write to the mailing list typo3.teams.bugs with issue number and an explanation or open a new ticket and add a relation to this ticket number.