I've got Repository method which returns sum of missing invoices price to pay
public function getAmountToPay()
{
$query = $this->createQueryBuilder('i')
->select('c.name, (i.price - COALESCE(sum(p.amount), 0)) as price')
->leftJoin('i.payments', 'p')
->join('i.company', 'c')
->where('i.dueDate > :now')
->groupBy('i.id')
->having('sum(i.price) > SUM(p.amount) OR SUM(p.amount) IS NULL ')
->setParameter('now', new \DateTime())
->getQuery();
return $query->getResult();
}
Pure SQL returns normal rows but if I do it in doctrine, it returns some weird data in array with 0 values:
"afterDeadline" => array:3 [▼
0 => array:2 [▼
"name" => "Example company #1"
"price" => "0"
]
1 => array:2 [▼
"name" => "Example company #2"
"price" => "0"
]
2 => array:2 [▼
"name" => "Example company #1"
"price" => "117.99000000000001"
]
Why it has companies with 0 value? Only the last array index is ok.