Habtm and counter (xxx_count field in DB)


#1

Hi all

I have the following models:

class Member < ActiveRecord::Base

DJ Profiles the member is part of

has_and_belongs_to_many :disc_jockeys,
:join_table => ‘members_are_disc_jockeys’,
:uniq => true
end

class DiscJockey < ActiveRecord::Base

Members that are part of this DJ profile

has_and_belongs_to_many :members,
:join_table => ‘members_are_disc_jockeys’,
:uniq => true
end

I tried to add such a xxx_count field to have a counter cache, so I
added the field disc_jockeys_count to the members table. But sadly this
doesn’t become updated when adding a DJ object to a member…

What’s wrong? Thanks.
Josh