Need to update books_count column for authors somehow

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

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

On 8/22/06, DAN [email protected] 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

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