Search code examples
mysqldoctrinedoctrine-ormsum

Doctrine 2 SUM() equivalent helper?


Strange, there is no SUM() equivalent in Doctrine2 helpers? There is max, min, count... am i blind?

// Example - $qb->expr()->avg('u.age')
public function avg($x); // Returns Expr\Func

// Example - $qb->expr()->max('u.age')
public function max($x); // Returns Expr\Func

// Example - $qb->expr()->min('u.age')
public function min($x); // Returns Expr\Func

// Example - $qb->expr()->abs('u.currentBalance')
public function abs($x); // Returns Expr\Func

// Example - $qb->expr()->sqrt('u.currentBalance')
public function sqrt($x); // Returns Expr\Func

// Example - $qb->expr()->count('u.firstname')
public function count($x); // Returns Expr\Func

Solution

  • There does not appear to be a sum() helper. You can still use SUM in QueryBuilder; e.g:

    $qb->add('select', 'SUM(u.id)')
       ->add('from', 'User u')