2
votes

I am building an extension with a backend module. When I call the findAll() method it returns a "QueryResult" object.

I tried to retrieve objects with findByUid() and it does work.

I set the storage pid in the typoscript:

plugin.tx_hwforms.persistence.storagePid = 112

I can also see it in the typoscript object browser.

I also added this to my repository class:

public function initializeObject()
    {
        $defaultQuerySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class);
        $defaultQuerySettings->setRespectStoragePage(false);
        $this->setDefaultQuerySettings($defaultQuerySettings);
    }

so that the storage pid is ignored ... It's still not working, findAll doesn't return an array of entites as it should

5
seems to be ok the snippet above. Are you sure that you have records in the table related to this repository ?Andrei Todorut
Hi Andrei, yes I am sure. I also tried to use a repository from another extension where findAll() is working fine. And I notice it is also not working, so for some reason findAll isn't working at all in my extension.user6800816
so, var_dump ( use the function from extbase ) the $GLOBALS['TYPO3_DB'] after calling the findAll() function and check the last query buildAndrei Todorut
I tried that but it completely ignores the findAll method. It works with other repository methods like findByUid or even findAll()->count ... which doesnt make any sense to meuser6800816
weird. Is your repository extends TYPO3::CMS::Extbase::Persistence::Repository ? Have you check for name spelling between repository, model and tablename ?Andrei Todorut

5 Answers

4
votes

Repository must return a QueryResult from the findAll methods. Only methods which return a single object (findOneByXYZ) will return anything else.

All of the following operations will cause a QueryResult to load the actual results it contains. Until you perform one of these, no results are loaded and debugging the QueryResult will yield no information except for the original Query.

  • $queryResult->toArray();
  • $queryResult->offsetGet($offset); and $queryResult[$offset];
  • $queryResult->offsetExists($offset);
  • $queryResult->offsetSet($offset, $value); and $queryResult[$offset] = $value; (but be aware that doing this yourself with a QueryResult is illogical).
  • $queryResult->offsetUnset($offset); and unset($queryResult[$offset]); (again, illogical to use this yourself)
  • $queryResult->current(), ->key(), ->next(), ->prev(), ->rewind() and ->valid() which can all be called directly or will be called if you begin iterating the QueryResult.

Note that ->getFirst() and ->count() do not cause the original query to fire and will not fill results if they are not already filled. Instead, they will perform an optimised query.

Summa summarum: when you get a QueryResult you must trigger it somehow, which normally happens when you begin to render the result set. It is not a prefilled array; it is a dynamically filled Iterator.

3
votes

This should work.there must be issue with your storage page in FindAll() extbase check for storage but in findByXXX() it ignore storage.

$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\Extbase\\Object\\ObjectManager');
$querySettings = $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
$querySettings->setRespectStoragePage(FALSE);

$this->cityRepository->setDefaultQuerySettings($querySettings);
$cities = $this->cityRepository->findAll();
2
votes

Use additionally typoscript module configuration, like

module.tx_hwforms.persistence.storagePid = 112

Ensure your Typoscript is loaded in root. For BE modules I prefere to use

EXT:hwforms/ext_typoscript_setup.txt

where you write your module and extbase configuration.

1
votes

Try to debbug like below and check findAll() method present for this repositry. I think this is useful for you click here

\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(get_class_methods($this->yourRepositryName)); exit();

Afetr added all your changes once you need to uninsatll/install extension.

1
votes

I would inspect the generated query itself. Configure the following option in the install tool:

$GLOBALS["TYPO3_CONF_VARS"]["sqlDebug"]

Note: dont do this in production environemnt!!

Explanation for sqlDebug:

Setting it to "0" will avoid any information being print on screen.

Setting it to "1" will show errors only.

Setting it to "2" will print all queries on screen.

So in Production you want to keep it at "0", in development environments you should set it to "1", if you want to know why some result is empty, configure it to "2".

I would guess that some enablefield configuration causes your problem.

If you retrieve an object by findByUid you will have the return because enablefields are ignored. In every other case enablefields are applied and that may cause your empty result.