[Flow] Generate sum-column with doctrine
Christian Loock
chl at vkf-renzel.de
Wed Apr 9 12:47:17 CEST 2014
This logic makes no sense inside the model itself, since the model
always describes a single entity.
In my oppinion, this belongs inside the repository. Build your DQL there
inside a seperate method.
On 09.04.2014 12:46, Johannes Steu wrote:
> Hey Folks,
>
> i'm running in a problem. My model has a column with an integer. I'd like to get a sum of all models for this.
> I Could do a foreach, iterate all models and sum the values up. But i'll have a huge amount of objects to sum up. So i think a native SQL-Query with a sum()-Function would give me much more performance.
>
> How can i implement this best with Flow? I found this article about aggregate Fields [1]. They describe the foreach-option and also an DQL-Statement.
> So the DQL-Statement is what i'm looking for. But how and specially where to implement this best? Should i run the query inside the model when calling the getter function? I would have to inject the Doctrine's EntityManager inside the model. Is this ok or a no go?
>
> Is there a cleaner and easier way with an doctrine-annotation? Just like:
> /**
> * @var int
> * @ORM\SUM("diff")
> */
> protected $total
>
> while diff being the column i'd like to sum up and total the SUM()-Result.
>
> Thanks for you help,
> Johannes
>
>
> [1] http://docs.doctrine-project.org/en/2.0.x/cookbook/aggregate-fields.html
>
> --
> Wittener Str. 63
> 44149 Dortmund
>
> @stolle_
>
> ---------------------------------------------------------
> This E-Mai is signed with OpenPGP
> Pub-Key: 6407EBEA
>
>
>
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
--
Christian Loock
Web Developer
Renzel Agentur
www.renzel-agentur.de
More information about the Flow
mailing list