How to count Items of related object

Hi All,

I want to count total items of related object.

I have the following relations

In Categories Model


In Plans Model


Please let me know How I can count total Plans does a category have?

Make it worked Using

countByAttributes as


Anyone knows the better way to do it?

Did you look at statistical queries? Before you use them, you should probably make sure, you understand, what they do: They can increase the number of queries sent to your DB. Actually i never use them and instead use group + a custom select field to get the count of related items in a single query. Note, that with GROUP BY you can only count the number of objects for one relation.

Thanks mike.