I have a model called Partners and a model called Profiles.
A partner has many profiles and a profile has one partner.
I need a way to count in the partners controller to return how many profiles they have.
In the profiles table the column is called : partner_id which is the same as the id column in the partners table.
I have seen the .count() function but cannot work out what I need to return the correct number
Cheers
I think the best way will be to use
counter_cachecolumn:you should add
profiles_countcolumn topartnerstable. It’s not a good way to call@partner.profiles.countbecause it will perform additional query to the database. You should use@partner.profiles.sizeinstead. It will get size of collection if it has been already retrieved from the database and perform query in another case.For more details please visit following links: