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

Stephan Schuler Stephan.Schuler at netlogix.de
Wed Apr 10 12:44:22 CEST 2013


Hey there.

Usually the SQL level is not the thing you want to influence.
When using an extbase repository, you never deal with "some records" but you always deal with model object. And an instance of a model class is a PHP object with properties. If they are available in the PHP code, you expect them to be completely present and filled, content wise. Usually you don't want to distinguish environments (something like "completely filled" and "partially filled because of reduced environment set").

Think about having an object "Language" that has the properties "isoCode", "nativeTitle" and "englishTitle". I don't know if that's like your language model is designed, but that could be.
Now think about a reduced mapping for REST that only contains "isoCode" and "nativeTitle" but not "englishTitle".
Try to update your object, set "nativTitle" to something different (maybe because of a spelling issue) and push this object to $repository->update.
What's the deal with "englishTitle". It's empty, and the object is dirty. So it has to be written to the database. Are you trying to update "englishTitle" to an empty string (which is perfectly valid if you want exactly that to happen) or has the repository to ignore the "englishTitle" property?

So, please don't try to create partially filled objects. This will lead to confusion at some point.

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.

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.

You can even combine those things: Make a SimpleLanguage object that contains only the "title" property and a "Language" object which contains more properties and extends the SimpleLanguage. By TypoScript you can map both class names to the same database table and give them the very same type discriminator. Just make sure there is always exactly one of them available at a time. Maybe switch them by PidInRootline.

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.

So, could you please explain a bit more where and why exactly you're doing ajax that contains too much information?

Regards,



Stephan Schuler
Web-Entwickler

Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Website: media.netlogix.de



--
netlogix GmbH & Co. KG
IT-Services | IT-Training | Media
Andernacher Straße 53 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: info at netlogix.de | Internet: http://www.netlogix.de

netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt



-----Ursprüngliche Nachricht-----
Von: typo3-project-typo3v4mvc-bounces at lists.typo3.org [mailto:typo3-project-typo3v4mvc-bounces at lists.typo3.org] Im Auftrag von Philipp
Gesendet: Mittwoch, 10. April 2013 10:43
An: typo3-project-typo3v4mvc at lists.typo3.org
Betreff: [TYPO3-mvc] Re: Re: extbase query select only specific table columns

Quote: Domi Garms wrote on Tue, 09 April 2013 14:47
----------------------------------------------------
> On 04/09/2013 03:09 PM, Philipp wrote:
> > I dont think so, but if you really need those 2 columns only in a
> > resultarray you may send a raw statement. No need for a mapping
> > process here if you just handle one string and one integer.
> Hi Philipp,
>
> I did this now:
>
> $query     = $this->createQuery();
> $selectQuery = 'SELECT id,name FROM mytable'
> $query->statement($selectQuery);
>
> return $query->execute()->toArray();
>
> Now my result is still an array of all rows, maybe because of toArray()?
> How can I get an array from my select without all unnecessary columns?
>
> Thanks,
> Dominic
----------------------------------------------------

$GLOBALS['TYPO3_DB']->exec_SELECTquery(); i think.... this is the most direct way respecting the DBAL _______________________________________________
TYPO3-project-typo3v4mvc mailing list
TYPO3-project-typo3v4mvc at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc


More information about the TYPO3-project-typo3v4mvc mailing list