Bug #62518

Wrong result count

Added by Natalia Postnikova almost 7 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2014-10-28
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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
}

#1

Updated by Stefan Froemken almost 7 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

#2

Updated by Natalia Postnikova almost 7 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.

#3

Updated by Stefan Froemken almost 7 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

#4

Updated by Wouter Wolters over 6 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.

Also available in: Atom PDF