Hi MYRZ

> Say, i have multiple customers. Customers have each a number of
> projects running. In each project, their are several Tickets. And some
> tickets together form an Invoice.
> 
> So you get:
> 
> Customer=[HasMany]=>Projects=[HasMany]=>Tickets=[BelongsTo]=>Invoices
> 
> Now, somehow i want to get all the invoices of the customer with the
> id $id. How should i do that? Just do
> 
> $clients = $this->Client->findAll('Client.id = '.$id, NULL, NULL,
> NULL, NULL,4);
> 
> , and overload my db, or is there an efficient way of doing this?

1. If your customer has LOTS of projects/tickets/invoices, then I would 
be adding a belongsTo association between Invoices and Customers.  That 
would let you select invoices with only one level of recursion.

2. You could use a custom query to join the three tables (Projects, 
Tickets, Invoices) and select the invoices.  Useful perhaps if you don't 
have huge numbers of records.

3. If you have relatively few records per customer, then as you suggest, 
just select the customer and get their whole history.  The manual 
suggests that recursion will only give you up to three level, so this 
would work in this instance, but not if you wanted to go deeper.


My money would be on adding an association between customer and invoice. 
  It seems like the clearest most logical approach to me given the 
nature of the data.

Regards,
Langdon

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to