We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Sum column got from getRelated

Is it possible to Sum column from Phalcon\Mvc\Model\Resultset\Simple. For example

$RobotParts = $this->getRelated('RobotsParts', $parameters);

What would be best way to get Sum from $RobotParts?



145.0k
Accepted
answer
edited Apr '16

You mean count ? Imho best way will be to :

$sumRobotParts = RobotsParts::sum($parameters);

Or count if you mean count.

If you have many robotparts then this will mean it need to select EVERY ROBOT PARTS. It will cost more time then doing just count/sum on RobotsParts. Try to avoid getRelated as much as you can. Use it only if you need to update related records IMHO.