Remove Poll::Voter record when there is no more user answers

Now we can remove answers we should provide a way of removing voting.
This commit is contained in:
Senén Rodero Rodríguez
2022-09-11 18:57:05 +02:00
parent 7df0e9a961
commit 3da4112d94
4 changed files with 73 additions and 11 deletions

View File

@@ -23,6 +23,16 @@ class Poll::Answer < ApplicationRecord
end
end
def destroy_and_remove_voter_participation
transaction do
destroy!
if author.poll_answers.where(question_id: poll.question_ids).none?
Poll::Voter.find_by(user: author, poll: poll, origin: "web").destroy!
end
end
end
private
def max_votes