Generic-user-small Frank 6 posts

Hi Ryan i just finished watching the first 4 episodes of everyday activerecord. I really enjoyed them and I learned a lot.

I have a question regarding the callbacks episode. Near the end of the episode you modified the callback called clear_movie_average_stars_cache to handle the case where a review is moved from one movie to another. I think I fully understand that part. But what about the reviews_count ? Does that get automatically adjusted when you move a review from one movie to another due to :counter_cache => true ? I was under the impression that :counter_cache => true only changes the count for create and destroy.

- thanks,
Francois

 
Ryan_bates_cropped_small Ryan Bates 25 posts

Good question. The counter_cache does handle the case of moving a review from one movie to another. However it does not do it using callbacks – it is deeper ingrained inside the code itself. Specifically in the BelongsToAssociation#replace method.

2 posts, 2 voices