Rails beginner
Rails beginner

Reputation: 14514

Rails cached column dont get updated on destroy - Has many through

I want to count how many tags that belongs to konkurrancer. It is a has_many through Tagsmenu relation ship.

I have added the column konkurrancers_count to my Tags table.

Here is my join model:

class Tagsmenu < ActiveRecord::Base
  belongs_to :konkurrancer, :counter_cache => :true
  belongs_to :tag
end

But when I destroy a konkurrancer the konkurrancers_count column dont get updated.

Upvotes: 0

Views: 130

Answers (2)

bor1s
bor1s

Reputation: 4113

Take a look at this methods: update_counters

Upvotes: 0

Jonathan del Strother
Jonathan del Strother

Reputation: 2572

if you delete a record it just runs the deletion sql. If you destroy a record, it will instantiate the model, run all the callbacks, and then run the deletion sql. I think you'll find that you need to use destroy in order to see the cache column update.

Upvotes: 1

Related Questions