Question about Relational Active Record and STAT
Posted 13 April 2010 - 04:13 AM
path // it uses IP notation like 001.003.001 for ordering.
items look like this
path //it is path of category
i want to count items in categories using (it is part of relations array):
'itemCount' => array(self::STAT, 'Item', 'id_category','condition'=>'path LIKE '.$this->tableName().'.path%'),
but for example
category with path .001. should count all items with contain .001. at begging of the path for example:
How can i do that??
Posted 13 April 2010 - 05:10 AM
I know I can use composite pattern and then use "with" recurrently to get all sub categories, but isn't it more complex? With many subcategories it would have to add a lot of queries, and still it do not solves problem with number of items in all subcategories.
I already have ordering (i have defined paths), but i want to use relations array to define items count. when i use relations array i have to specify foreign key, so i can't count products which are under current category and all subcategories, because it uses this foreign key. I know i can archive this by public function in category model class, but if it is possible with relations array i would prefer to use it.
Posted 13 April 2010 - 05:28 AM
When inserting or deleting items you'll have to update counters of all ancestors, but it's not that hard operation as counting items for all categories every time they are being retrieved (especially in your case, when you have to search a substring).
Posted 13 April 2010 - 05:54 AM
'subcategories' => array(self::HAS_MANY, get_class($this), 'id_parent','with'=>'subcategories','order'=>'ordering')
Mysql server couldn't handle it. Although there is only 1 root category with 2 subcategories on second level and 3 on third.