I'm writing an invoicing application in CodeIgniter/DataMapper.
Each customer has many invoices.
In the view, I want to be able to display customer data and then a table of the invoices for that customer.
At the moment, I load the customer and their related invoices in the controller and send them to the view.
public function view($id) {
$c = new Customer($id);
$c->invoice->get_iterated();
$data['customer'] = $c;
}
But when I iterate over the invoices to display them in the view, I really want them to be in descending order by date, but of course they're not.
Is there any way to specify the order of related items or to sort them before displaying them, or do I need to load the invoices separately, something like in the following the controller?
public function view($id) {
$c = new Customer($id);
$i = new Invoice();
$i->order_by('invoice_date', 'desc');
$i->get_where(array('customer_id' => $id));
$data['customer'] = $c;
$data['invoices'] = $i;
}