This is the first project im working on, where i am using dmz. I tried Doctrine and Rapidmapper, but they didn't quite meet my needs as well as dmz seems to. DMZ has already helped me alot when im working with quite complex relations, but what i didnt find from the user manual, is how to work with collections inside collections inside collections...
Do you always have to go with foreach loops, e.g. if i want to create invoices based on every transaction that has been made in the past 24 hours, and get the related data to this invoice, do i have go like this:
Code:
$transactions = new Transaction();
// Get all the transactions created in the past 24h
$transactions->where("HOUR( TIMEDIFF( NOW( ) , `transactions`.`created` )) < 24")->get();
foreach($transactions as $transaction) {
//Get all related data
$transaction->invoice->get(); //Transaction has one invoice
$transaction->invoice->invoice_line->where('gl_account_id',3000)->or_where('gl_account_id',3002)->get(); //Invoice has many invoice_lines
foreach($transaction->invoice->invoice_line as $invoice_line){
$invoice_line->gl_account->get(); //Invoice_line has an gl_account
}
And if thats not all the relations, it just seems like there is a better way to do these things, i just haven't really figured it out. I have tried with the include_related, but e.g. if the invoice table has an in-table foreign key for an transaction, then i cant do this
Code:
$t = new Transaction(); $t->include_related('invoice',null,false,true); // This has all the values as null of related invoice object
$i = new Invoice(); $i->include_related('transaction', null, false, true) // This works
I guess i'm just a bit confused about the correct usage with collections of collection.
Any help or guiding is really appreciated (and i have read the user manual many times already)