diff --git a/app/models/heart.rb b/app/models/heart.rb index c811f80..f598d1c 100644 --- a/app/models/heart.rb +++ b/app/models/heart.rb @@ -24,9 +24,11 @@ class Heart < (defined?(ApplicationRecord) == 'constant' ? ApplicationRecord : A belongs_to :heartable, :polymorphic => true belongs_to :user + attribute :skip_validate_user, :boolean + validates_presence_of :user validates_uniqueness_of :user_id, :scope => [:heartable_type, :heartable_id] - validate :validate_user + validate :validate_user, :unless => :skip_validate_user def self.of_projects(*args) projects = args.size > 0 ? args.shift : Project.none diff --git a/lib/tasks/redmine_hearts.rake b/lib/tasks/redmine_hearts.rake index 891fbf5..7d16227 100644 --- a/lib/tasks/redmine_hearts.rake +++ b/lib/tasks/redmine_hearts.rake @@ -88,7 +88,7 @@ namespace :redmine_hearts do num_of_heart_before_processing = Heart.count - VoteOnIssue.where('vote_val > 0').each do |vote| + VoteOnIssue.where('vote_val > 0').where.not(issue: nil, user: nil).each do |vote| issue = vote.issue user = vote.user datetime = vote.created_at || Time.now @@ -100,6 +100,7 @@ namespace :redmine_hearts do :user => user, :created_at => datetime, :updated_at => datetime, + :skip_validate_user => true, ) end end