Forum: Ruby on Rails counter cache problem

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.
pankaj (Guest)
on 2009-03-07 14:24
(Received via mailing list)
Here is the problem
There is a gallery model and image model
gallery has many images
gallery has images_count.

When I change image from one gallery to another i have to update the
counter cache(It does not happen automatically on doing
gallery2.images << image).
So i do
gallery1.images_count -= 1
gallery2.images_count += 1

but this still does not update the count of the images

when i see the log files, the update queries are fired, but they
update only the updated_at column and not the images_count column.
The same thing works when done through console.
Can any one explain why this is happening?

Billy H. (Guest)
on 2009-03-07 14:32
(Received via mailing list)
has_many :images, :counter_cache => true

On Sat, Mar 7, 2009 at 8:23 PM, pankaj <removed_email_address@domain.invalid> 

> gallery1.images_count -= 1
> Regards,
> Pankaj
> >

Only two surfaces of a box:
pankaj (Guest)
on 2009-03-07 18:20
(Received via mailing list)
I have already added :counter_cache with the belongs to relationship,
it cannot be added with has_many.
Any ways I am updating the counter manually, and it is not happening.
This topic is locked and can not be replied to.