removes answer <-> voter association

This commit is contained in:
Juanjo Bazán
2017-01-27 11:59:37 +01:00
parent ce7bac4a59
commit 51be80eedc
4 changed files with 13 additions and 15 deletions

View File

@@ -3,8 +3,6 @@ class Poll::Answer < ActiveRecord::Base
belongs_to :question, -> { with_hidden }
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
has_one :voter
delegate :poll, :poll_id, to: :question
validates :question, presence: true
@@ -16,6 +14,6 @@ class Poll::Answer < ActiveRecord::Base
scope :by_question, -> (question_id) { where(question_id: question_id) }
def record_voter_participation
Poll::Voter.create_from_user(author, {poll_id: poll_id, answer_id: id})
Poll::Voter.create_from_user(author, {poll_id: poll_id})
end
end

View File

@@ -2,7 +2,6 @@ class Poll
class Voter < ActiveRecord::Base
belongs_to :poll
belongs_to :booth_assignment
belongs_to :answer
validates :poll, presence: true
validates :document_number, presence: true, uniqueness: { scope: [:poll_id, :document_type], message: :has_voted }
@@ -26,7 +25,6 @@ class Poll
def self.create_from_user(user, options = {})
poll_id = options[:poll_id]
booth_assignment_id = options[:booth_assignment_id]
answer_id = options[:answer_id]
Voter.create(
document_type: user.document_type,
@@ -35,8 +33,7 @@ class Poll
booth_assignment_id: booth_assignment_id,
gender: user.gender,
geozone_id: user.geozone_id,
age: user.age,
answer_id: answer_id
age: user.age
)
end