Hi
the table-structure:
Supplier -> 1:n -> Invoices -> 1:n -> InvoiceItems
Now i want to display a paginated list with the columns: invoice.id, supplier.name, SUM(invoiceitem.price)
Realy easy every-day-task, but (again) i don't know how to realize this with Phalcon. I can find some examples for each part of this requirement (Join, Pagination, Sum), but i can't find anything about how to combine these 3 parts.
Pagination and Join to Supplier works well:
// controller
<?php
$queryBuilder = $this->modelsManager->createBuilder()
->from('Invoices')
->join('Suppliers')
;
$paginator = new Phalcon\Paginator\Adapter\QueryBuilder([
"builder" => $queryBuilder,
"limit" => 20,
"page" => 1
]);
?>
// view
<?php foreach ($paginator->items as $invoice): $supplier = $invoice->Suppliers; ?>
<?= $invoice->id ?>
<?= $supplier->name ?>
<?php endforeach ?>
But adding the aggregate Column doesn't work as expected and i can't find anything similar in the docs. I tried:
$queryBuilder = $this->modelsManager->createBuilder()
->from('Invoices')
->join('Suppliers')
->join('InvoiceItems')
->columns([
'Invoices.*',
'Suppliers.*',
'SUM(InvoiceItems.price)',
])
->groupBy('Invoices.id')
;
$paginator = new Phalcon\Paginator\Adapter\QueryBuilder([
"builder" => $queryBuilder,
"limit" => 20,
"page" => 1
]);
This results in Phalcon\Mvc\Model\Row where i can't access any imaginable property. Neither $row->id nor $row->Suppliers are existent.
So what's wrong or what am i missing? Is there an other Solution for such a list?