I have following models: Category
, SubCategory
, Product
, User
and CategoryPerUser
.
Below is corresponding ER diagram:
Here is a brief explanation of what I want to achieve:
a product belongs to a sub_category which belongs to a category
a user can upload many products
in category_per_user, I want to keep user uploaded articles per category count
For now I wrote a method in Product model which updates CategoryPerUser.products_count
whenever a user add a new product.
Is there a way to set this logic using counter-cache
or counter-culture
?
Or should I change my ER ?
Thanks in advance,