[TYPO3-mvc] order by "calculated attribute" - several approaches

Christian Baer chr.baer at googlemail.com
Mon Jun 7 09:40:47 CEST 2010


Hey,

I'm not quite sure where to put the logic for a calculated attribute.

I have two tables, clips and ratings, which are connected via M-M. Clips 
can be rated with a value from 1 to 5. Now I'd like to have the 
calculated field "average_rating", which shows the average of all 
ratings for one clip. But it's only a calculated attribute, nothing is 
stored. What I need now is something like "order Clips by average_rating".

I have several approaches:

1. fetch all clips and calculate the average_rating in PHP
2. fetch all clips ordered via a SQL-statement
3. create an expression in SQL, which calculates the average

With the first two approaches I cannot use the normal 
Extbase-Repository-Querys, which is quite bad. The third one puts the 
logic into SQL, which I don't really prefer.

Now, is there a Extbase-way to handle this? Is there a way to add an 
attribute to the Clip-Model, which calculates the average and then could 
be used in $query->setOrderings(...)? Maybe adjust something in the 
Mapping-process?



Regards,
Chris



More information about the TYPO3-project-typo3v4mvc mailing list