Counter_cache and collections

I’ve got a has_many/belongs_to association between two Rails models
and I’m caching the child counter in the parent model via a
counter_cache. When adding a child to the parent via the ‘<<’ method
of the parent, I was expecting the in-memory child counter in the
parent to be updated, but it doesn’t appear as though it is. My
controller code looks something like this:

def create
@flag =[:flag])
@flag.user = authenticated_user
@listing = Listing.find(params[:listing_id])
@listing.flags << @flag

If I add a call to after adding the child to the parent,
the in-memory counter is updated, but I didn’t think the call to
‘save’ was necessary. Am I doing something wrong or is this WAD?

I also tried

def create
@listing = Listing.find(params[:listing_id])
@flag = listing.flags.create(params[:flag])
@flag.user = authenticated_user

but that didn’t do the trick either. The odd thing is when I try
something similar in script/console, sometimes @listing.flags.size ==
1 after the call to listing.flags.create and sometimes it remains at
0. I should also mention that the flag model uses the acts_as_tree
plugin in Rails 2.0, but does not use the counter_cache option of the