diff --git a/db/migrate/20110527135552_photo_status_message_association_on_guid.rb b/db/migrate/20110527135552_photo_status_message_association_on_guid.rb index d6c16c3ee..d5b442588 100644 --- a/db/migrate/20110527135552_photo_status_message_association_on_guid.rb +++ b/db/migrate/20110527135552_photo_status_message_association_on_guid.rb @@ -9,8 +9,10 @@ class PhotoStatusMessageAssociationOnGuid < ActiveRecord::Migration photos = Post.where(Post.arel_table[:status_message_id].not_eq(nil).and(Post.arel_table[:type].eq('Photo'))) photos.each do |photo| - status_message = Post.find(photo.status_message_id) - photo.update_attributes(:status_message_guid => status_message.guid) + if Post.where(:id => photo.status_message_id).exists? + status_message = Post.find(photo.status_message_id) + photo.update_attributes(:status_message_guid => status_message.guid) + end end remove_index :posts, [:status_message_id, :pending] @@ -25,8 +27,10 @@ class PhotoStatusMessageAssociationOnGuid < ActiveRecord::Migration photos = Post.where(Post.arel_table[:status_message_guid].not_eq(nil).and(Post.arel_table[:type].eq('Photo'))) photos.each do |photo| - status_message = Post.where(:guid => photo.status_message_guid).first - photo.update_attributes(:status_message_id => status_message.id) + if Post.where(:guid => photo.status_message_guid).exists? + status_message = Post.where(:guid => photo.status_message_guid).first + photo.update_attributes(:status_message_id => status_message.id) + end end remove_index :posts, [:status_message_guid, :pending]