[TYPO3-mvc] Limit ignored in query
Stephen Bungert
stephenbungert at yahoo.de
Sat Jan 19 17:50:22 CET 2013
My repository function is setting a limit (of 1) but is not being used.
When I run the same query in phpmyadmin only 1 record is returned. But
Extbase returns three records... strangely this is not all records, I
have 5 currently. Does anyone know why it is not returning just 1 record
like I wanted?
I debugged the query, here it is:
SELECT tx_sbportfolio2_domain_model_item.*
FROM tx_sbportfolio2_domain_model_item
WHERE tx_sbportfolio2_domain_model_item.inprogress = '0'
AND tx_sbportfolio2_domain_model_item.deleted = 0
AND tx_sbportfolio2_domain_model_item.t3ver_state <= 0
AND tx_sbportfolio2_domain_model_item.pid <>- 1
AND tx_sbportfolio2_domain_model_item.hidden = 0
AND tx_sbportfolio2_domain_model_item.starttime <= 1358612940
AND ( tx_sbportfolio2_domain_model_item.endtime = 0
OR tx_sbportfolio2_domain_model_item.endtime > 1358612940 )
AND tx_sbportfolio2_domain_model_item.sys_language_uid IN ( 0, -1 )
AND tx_sbportfolio2_domain_model_item.pid IN ( 3 )
LIMIT 1
And my repo function:
/**
* Finds all records, possibly restricting the search if TS/FF settings
require it
*
* @param array $portSetup The TS setup for the query.
* @return array An array of items
*/
public function findWithConstraints(array $portSetup) {
$limit = intval($portSetup['limit']);
$query = $this->createQuery();
// Handle featured and inprogress
if (isset($portSetup['featured']) || $portSetup['inprogress']) {
$featured = -1;
$inprogress = -1;
if ($portSetup['featured'] == 'exclude') {
$featured = 0;
} else if ($portSetup['featured'] == 'only') {
$featured = 1;
} // Else 'include' - don't add any constraint
if ($portSetup['inprogress'] == 'exclude') {
$inprogress = 0;
} else if ($portSetup['inprogress'] == 'only') {
$inprogress = 1;
} // Else 'include' - don't add any constraint
if ($featured >= 0 && $inprogress >= 0) { // Featured && Inprogress
$query->matching(
$query->logicalAnd(
$query->equals('inprogress', $inprogress),
$query->equals('featured', $featured)
)
);
} else if ($featured == -1 && $inprogress >= 0) { // Inprogress
$query->matching($query->equals('inprogress', $inprogress));
} else if ($featured >= 0 && $inprogress == -1) { // Featured
$query->matching($query->equals('featured', $featured));
}
}
if ($limit >= 1) {
$query->setLimit($limit);
}
return $query->execute();
}
More information about the TYPO3-project-typo3v4mvc
mailing list