Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?

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.