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.new(params[:flag]) @flag.user = authenticated_user @listing = Listing.find(params[:listing_id]) @listing.flags << @flag end
If I add a call to @listing.save 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?