deletecandidates = User.where(protected: false).where.not(id: 1) deletecandidates.find_each do |user| 	next if Ticket.where(customer_id: user.id).count > 0         puts %{ "#{user.fullname}" #{user.id} #{Ticket.where(customer_id: user.id).count}}          Ticket.where(customer: user).find_each do |ticket|     	    puts "  Deleting ticket ##{ticket.number}..."     	    ticket.destroy         end          puts "  Removing references for user with email #{user.email}..."     	ActivityStream.where(created_by_id: user.id).update_all(created_by_id: 1)         History.where(created_by_id: user.id).update_all(created_by_id: 1)         Ticket::Article.where(created_by_id: user.id).update_all(created_by_id: 1)         Ticket::Article.where(updated_by_id: user.id).update_all(updated_by_id: 1)         Store.where(created_by_id: user.id).update_all(created_by_id: 1)         StatsStore.where(created_by_id: user.id).update_all(created_by_id: 1)         Tag.where(created_by_id: user.id).update_all(created_by_id: 1)         OnlineNotification.find_by(user_id: user.id)&.destroy!          puts "  Deleting #{user.fullname}..."         user.destroy end 

'protected' is a custom user object attribute i did add.


This free site is ad-supported. Learn more