1 class FixLastPosts < ActiveRecord::Migration
2 class Topic < ActiveRecord::Base
3 has_many :posts, :order => 'posts.created_at'
5 class Post < ActiveRecord::Base; end
8 Topic.find(:all, :include => :posts).each do |topic|
9 post = topic.posts.last
11 Topic.update_all(['replied_at = ?, replied_by = ?, last_post_id = ?',
12 post.created_at, post.user_id, post.id], ['id = ?', topic.id]) if post