recursive statistical query

Hello Yii fellows,

hope, you can help me. I have two Models, "Categories" and "SubCategories", a category has many subcategories, an foreign key (categoryID) exists in SubCategories table. Furthermore I have projects, belonging to exactly one subcategory and thus implicitly one category.

shortly, the relations are:

Category --HAS_MANY–> SubCategory --HAS_MANY–> PROJECT

PROJECT -->HAS_ONE–> SubCategory --HAS_ONE–> Category

Following the guide http://www.yiiframework.com/doc/guide/database.arr in section "Statistical Query" it was an ease to get the count of projects for a certain subcategory.

The problem is that I need the project count for a certain category as well on another place. I could simply achieve this by adding the project counts for every subcategory of the current category, but I was wondering, if it is possible to utilize the STAT skills of Yii, doing this kind of recursive statistical query for me.

Best regards,

Bergtroll

I am in a similar situation, requiring a stat query on a second level related value. This seems to be a common use case.

this will help

http://www.yiiframework.com/doc/guide/1.1/en/database.arr#relational-query-with-through

Gustavo, can you please tell us how to use through specifically for this problem? I’ve a similar problem which I explained here: http://www.yiiframework.com/forum/index.php/topic/32769-recursive-statistical-query/

Do you think through can be used for such a requirement? or are there any other alternatives?