Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AddTargetFieldsToGalleryPicture < ActiveRecord::Migration
- def self.up
- add_column :gallery_pictures, :target_id, :integer
- add_column :gallery_pictures, :target_type, :string
- GalleryPicture.where("gallery_id is not null").each do |picture|
- picture.target_type = "Gallery"
- picture.target_id = picture.gallery_id
- picture.save
- end
- remove_column :gallery_pictures, :gallery_id
- end
- def self.down
- add_column :gallery_pictures, :gallery_id, :integer
- GalleryPicture.where(:target_type => "Gallery").each do |picture|
- picture.gallery_id = picture.target_id
- picture.save
- end
- add_column :gallery_pictures, :gallery_id, :integer
- remove_column :gallery_pictures, :target_id
- remove_column :gallery_pictures, :target_type
- end
- end
Add Comment
Please, Sign In to add comment