Skip to content

A platform for community discussion. Free, open, simple.

836 B
Raw Blame
# frozen_string_literal: true

class PollOption < ActiveRecord::Base
  belongs_to :poll
  has_many :poll_votes, dependent: :delete_all

  attr_writer :voters_count

  def voters_count
    return @voters_count if defined?(@voters_count)

    @voters_count = poll_votes.count
  end
end

# == Schema Information
#
# Table name: poll_options
#
#  id              :bigint           not null, primary key
#  anonymous_votes :integer
#  digest          :string           not null
#  html            :text             not null
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#  poll_id         :bigint
#
# Indexes
#
#  index_poll_options_on_poll_id             (poll_id)
#  index_poll_options_on_poll_id_and_digest  (poll_id,digest) UNIQUE
#
# Foreign Keys
#
#  fk_rails_...  (poll_id => polls.id)
#