Skip to content
Browse files

Only execute update if there are active users

  • Loading branch information...
1 parent 94be031 commit e7c05baf1dd25972744892957e306a7f46dd8984 @mischa78 committed
Showing with 4 additions and 3 deletions.
  1. +4 −3 db/migrate/20130628082245_populate_user_id_in_share_links.rb
View
7 db/migrate/20130628082245_populate_user_id_in_share_links.rb
@@ -1,8 +1,9 @@
class PopulateUserIdInShareLinks < ActiveRecord::Migration
def change
- if User.any? && ShareLink.any?
- user = User.where.not(:name => nil).first
- ShareLink.where(:user_id => nil).update_all(:user_id => user.id)
+ active_users = User.where.not(:name => nil)
+
+ if active_users.any? && ShareLink.any?
+ ShareLink.where(:user_id => nil).update_all(:user_id => active_users.first.id)
end
end
end

0 comments on commit e7c05ba

Please sign in to comment.
Something went wrong with that request. Please try again.