views:

25

answers:

0

I have a lot of has_many :through relations in my app. I am extensivley showing informations related to this, such as number of connected objects. Whenever user updates the relation, join table is modified, and I can catch this my Sweepers.

The problem is, that join table entries are deleted, not destroyed. If relation is gone, I have no resonable way to detect this, and I am displaying misleading informations from the cache. Everything like :touch => true, or :counter_cache => true works partialy. It's get incremented if relations are updated or created. But if user removes relation nothing happens. :counter_cache is getting broken, :touch doesn't trigger.

The garbage solution is to call .touch in the controller, when the main model is saved. This kind of works, but it seems really non-professional. This should be in the model logic, not in the controllers.

I feel like I am missing something big, but cant get my head over this. Anyone could put some insight on this problem?