my tables:
categories:
- category_id
- name
articles
- article_id
- title
- contnet
articles_categories:
- article_id
- category_id
now i want to get all categories with the number of articles in it.
now in my Category model i have something like this :
public function countContents($category_id){
$query = $this->query('SELECT COUNT(*) as how_many FROM '.$this-
>TABLE_CONTENTS_CATEGORIES.' WHERE category_id = '.$category_id);
return $query[0][0]['how_many'];
}
public function getAll(){
$data = array();
foreach($this->findAll() as $index => $category){
$data[$index]['Category'] = $category['Category'];
$data[$index]['Category']['how_many'] = $this-
>countContents($category['Category']['category_id']);
}
return $data;
}
but IMHO there's must be better way to do this..
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---