Since I''ve been developing my code and data at the same time my count columns are off. Some say 0 (the default) instead of the actual. Is there some way to run something like this in irb: puts "Refreshed size = #{author.books_count(:refresh).size}" except for all *_count columns in each table? I''m probably dreaming but it would be nice if there was a way to easily do this. Thanks, DAN -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dee Zsombor
2006-Aug-22 09:55 UTC
[Rails] Re: Need to update books_count column for authors somehow
DAN wrote:> Since I''ve been developing my code and data at the same time my count > columns are off. Some say 0 (the default) instead of the actual.You can have a small non schema changing migration, that loops over each author and does: author.update_attribute(:books_count, author.books.size) Zsombor -- Company - http://primalgrasp.com Thoughts - http://deezsombor.blogspot.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Isak Hansen
2006-Aug-22 10:15 UTC
[Rails] Re: Need to update books_count column for authors somehow
On 8/22/06, DAN <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Since I''ve been developing my code and data at the same time my count > columns are off. Some say 0 (the default) instead of the actual. > > Is there some way to run something like this in irb: > puts "Refreshed size = #{author.books_count(:refresh).size}" > except for all *_count columns in each table? > > I''m probably dreaming but it would be nice if there was a way to easily > do this.Denormalization is a bitch, huh? Considered dropping the count columns altogether? Isak --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
DAN
2006-Aug-22 17:25 UTC
[Rails] Re: Need to update books_count column for authors somehow
This seems to work in the irb console $ ruby script/console>> a = Author.find(:all)for i in a i.update_attribute(:books_count, i.books.size) i.update_attribute(:articles_count, i.articles.size) i.update_attribute(:lectures_count, i.lectures.size) end DAN -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---