I have the following task to run on Rais:
require 'net/http'
namespace :seed do
task :set_gid_on_histories => :environment do
History.all.each do |hist|
if hist.channel != "REMOTE"
if hist.guest
guest = Guest.find(hist.user_group_id)
hist.update_attributes(:group_id => guest.group_id)
else
ug = UserGroup.with_deleted.find(hist.user_group_id)
hist.update_attributes(:group_id => ug.group_id)
end
end
end
end
end
The problem happens in line
ug = UserGroup.with_deleted.find(hist.user_group_id)
What happens is that it's throwing
ActiveRecord::RecordNotFound: Couldn't find UserGroup with 'id'=71 [WHERE "user_groups"."deleted_at" IS NULL]
just as if there was no 'with deleted' on the command line.
I tried to type the same command on rails console and it worked, i.e. when I run ug = UserGroup.with_deleted.find(71) it works just fine and finds the deleted user.
So it seems that paranoia's 'with_deleted' command is not working on rails tasks... Am I missing something?