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 gallery1.save gallery2.save 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? Regards, Pankaj --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gallery.rb has_many :images, :counter_cache => true On Sat, Mar 7, 2009 at 8:23 PM, pankaj <pankajbhageria-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > gallery1.save > gallery2.save > > 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? > > > Regards, > Pankaj > > > > >-- Only two surfaces of a box: http://blog.pixnet.net/zusocfc --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. Regards, Pankaj On Mar 7, 5:30 pm, CFC <zuso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Gallery.rb > has_many :images, :counter_cache => true > > > > On Sat, Mar 7, 2009 at 8:23 PM, pankaj <pankajbhage...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 > > gallery1.save > > gallery2.save > > > 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? > > > Regards, > > Pankaj > > -- > Only two surfaces of a box:http://blog.pixnet.net/zusocfc--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---