Forum: Ruby on Rails habtm and counter (xxx_count field in DB)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Joshua M. (Guest)
on 2006-02-02 00:08
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

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

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.
This topic is locked and can not be replied to.