I have a HAS_MANY relation called "relationName",
So I can get all related models using
$model->relationName;
or using
$model->getRelated('relationName');
I can also get a subset of relatedModels, by adding params
$model->getRelated('relationName', true, array('fieldName'=>'val'));
So, I will get a subset of all related models, which fieldName = "val"
but how can I count them?
This idea looks like bad one (because it will take all models and then count them):
count($model->getRelated('relationName', true, array('fieldName'=>'val')));
I need something which will finally build query with COUNT(), and return result.
Using STAT relation is also looks like bad idea (because I already described relation in code, why should I duplicate the description of relation?)
So, is there any good solution to count related (HAS_MANY) models with dynamic params?