You can skip the App::import step completely. Your models are already  
associated, so $this->Product is already accessible. In fact,  
App::import doesn't do anything, it works like require_once(), you  
would still have to manually instantiate the imported model class  
yourself (i.e. App::import will not create $this->Product for you,  
you'd have to do $this->Product = new Product() yourself).

Hence your solution is already not bad, isn't it? You could even do it  
from the controller anytime:
$this->Manufacturer->Product->find('count', ...);

On 22 Sep 2008, at 01:41, ORCC wrote:

>
> I have a Manufacturer model having many Products. In order to return
> the number of Products of a Manufacturer I wrote the following method
> in Manufacturer:
>
> function countProducts() {
>    App::import('Model','Product');
>   $condition = Array('manufacturer_id' => $this->id)
>   return $this->Product->find('count',Array('conditions' =>
> $condition));
> }
>
> I would like to know if there is some way of getting the count of
> associated records without importing the associated model, but
> performing a recursive count.
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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