Sha256: 8df64fd0e620b9a367dcc36dcb8a8a0a22d56fe4add57503324fdf5dfcb6791d
Contents?: true
Size: 905 Bytes
Versions: 17
Compression:
Stored size: 905 Bytes
Contents
class MakeCommentsPolymorphic < ActiveRecord::Migration def self.up add_column :comments, :commentable_type, :string add_column :comments, :commentable_id, :integer add_index :comments, :commentable_id Comment.all.each do |comment| unless comment.page_id.blank? comment.commentable_type = 'Page' comment.commentable_id = comment.page_id comment.save end end # Clean up comment table. The index is removed automatically remove_column :comments, :page_id end def self.down add_column :comments, :page_id add_index :comments, :page_id Comment.all.each do |comment| if comment.commentable_type == 'Page' comment.page_id = comment.commentable_id comment.save end end remove_column :comments, :commentable_type, :string remove_column :comments, :commentable_id, :integer end end
Version data entries
17 entries across 17 versions & 1 rubygems