[Flow] Generate sum-column with doctrine
Johannes Steu
js at johannessteu.de
Wed Apr 9 12:51:38 CEST 2014
Hi,
thanks for your reply. What about this case:
the model with the SUM-column is hold by an other model (aggregate root with repo) in an doctrine \Doctrine\Common\Collections\ArrayCollection.
So there isn’t a repo for that model.
Am 09.04.2014 um 12:47 schrieb Christian Loock <chl at vkf-renzel.de>:
> 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
>
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
More information about the Flow
mailing list