Bug #37565
count doesnt work with statement
| Status: | Rejected | Start date: | 2012-05-29 | |
|---|---|---|---|---|
| Priority: | Should have | Due date: | ||
| Assignee: | Bastian Waidelich | % Done: | 0% |
|
| Category: | Extbase: Generic Persistence | |||
| Target version: | - | |||
| Has patch: | No | Tags: | ||
| Votes: | 0 |
Description
I have created an own repository function with a query statement like this:
@
$query = $this->createQuery();
$result = $query->statement('
SELECT * FROM tale WHERE delivery_order_number LIKE "'.$deliveryOrderNumber.'"
')->execute();
return $result;
@
When i $result->count() the items i get the total number of items stored in the database and not one item which should be correct. I added a screenshot of the debug output where you can see only one element (which is correct) and the count of 174 elements (which is not correct)
Related issues
| duplicated by Extbase MVC Framework - Bug #13829: <f:count> does not work correctly when counting QOI | Closed | 2011-03-14 |
History
Updated by Bastian Waidelich 12 months ago
- Status changed from New to Rejected
- Assignee set to Bastian Waidelich
- Priority changed from Must have to Should have
Hi Christopher,
one advantage of using the default QOM mechanism is that we can modify the query before executing. If you write custom statements, you will lose the abstraction from a concrete storage and there is no way for Extbase to reliably modify the query and change it to a count statement.
The solution would be to replace your code by:
1 public function findByDeliveryOrderNumber($deliveryOrderNumber) { 2 $query = $this->createQuery(); 3 return $query->like('deliveryOrderNumber', $deliveryOrderNumber)->execute(); 4 }
(preferably)
or create a second statement:
1 $result = $query->statement('COUNT(*) FROM tale WHERE delivery_order_number LIKE "' . $deliveryOrderNumber . '"')->execute();
Updated by Marc Bastian Heinrichs 12 months ago
This is a result using statement. Why not using the query object for this "simple" query?
Other possibility one: use querySettings->setReturnRawQueryResult(TRUE). then you get an array you could call count on.
Other possibility two: call e.g. queryresult->current() first to get the queryresult object initialized. then you could call queryresult->count()
Updated by Christopher Seidel 12 months ago
I need to use the statement because i need deleted and hidden records aswell. And i think is only possible using an own statement.
I am just confused why all records are counted
My workaround for this "problem":
count($this->shipmentRepository->findShipmentsByDeliveryOrderNumber($insertArray['deliveryOrderNumber'])->toArray())
Updated by Marc Bastian Heinrichs 12 months ago
See $query->getQuerySettings()->setRespectEnableFields(FALSE);