[TYPO3-mvc] extbase query select only specific table columns

Domi djgarms at gmail.com
Thu Apr 11 02:23:58 CEST 2013


Hey Stephan

thanks for your explanation, it will help me in my further development.

> The first thing I would like to know: Why is it important for you to have a limited model? If you exporting some json or xml, you can (and should) name each property to be exported. Tell the JsonView by configuration which properties are to be exported.
>
I have an ajax call for a search box. There are 5 repository queries 
involved and the output should be a json_encode array with all values 
inside. I thought the most performant way would be to select only 
specific  with all table columns and safe them in the return array directly:

return json_encode(
   array (
     'select1' => $this->travelRepository->findSelectboxValues(),
     'select2' => $this->branchRepository->findSelecboxValues(),
     (...)
   )
);

The whole 5 repositories as json_encoded array would be over couple of 
MB big, so this was not an option.

With the toArray() function of the model I can iterate with foreach 
through each repository and set the columns. But this results into 5 
foreach loops and does something what could be done directly with the 
database query.

I thought here it might be possible telling the extbase query for just 
picking the required tables into the select statement.

> The second thing: Maybe you can manipulate the mapping with TypoScript.
> Clean approach: Use a completely different model and repository class for your ajax call and make them use the exact same database table as your full blown model. Just create TypoScript which maps your AjaxLanguage class to the tx_yourextension_domain_model_language.
> Dirty approach: Use your existing model class, configure the "title" column in your TypoScript but no other property name. This leads to objects where some properties are simply NULL.
>
Thanks for the clean approach :) I'll keep it in mind if I will get in 
use for it.

> If you do or do not use the extbase stuff depends on which problem you are trying to solve. But I would avoid going both, extbase and raw sql for two different features of the same project. This most likely results in different behavior, maybe because of different validation configuration or views. There are view worse things than realizing "what the heck, why is the very same problem solved in three different versions here", which is an indicator for having spent time in solving problems multiple times and the need for spending even more time to fix one single bug in several different parts of your code -- a very good chance for regression.
>
I will consider using $GLOBALS['TYPO3_DB']->exec_SELECTquery(); and not 
touch the extbase stuff, maybe this will be the way to go. Currently 
everything works in my ajax call.

Have a good day,

Dominic


More information about the TYPO3-project-typo3v4mvc mailing list