[Flow] Generate sum-column with doctrine
Johannes Steu
js at johannessteu.de
Wed Apr 9 12:46:12 CEST 2014
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
More information about the Flow
mailing list