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

Dmitri Pisarev dimaip at gmail.com
Mon Jun 7 13:29:49 CEST 2010


On 07.06.2010 11:40, Christian Baer wrote:
> 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
>
Hi Chris!
Maybe you can implement the sorting in getter or in the viewhelper?

Dmitri.


More information about the TYPO3-project-typo3v4mvc mailing list