2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-19 21:50:00 +08:00
|
|
|
class PollOption < ActiveRecord::Base
|
|
|
|
belongs_to :poll
|
|
|
|
has_many :poll_votes, dependent: :delete_all
|
2024-09-10 23:41:08 +08:00
|
|
|
|
|
|
|
attr_writer :voters_count
|
|
|
|
|
|
|
|
def voters_count
|
|
|
|
return @voters_count if defined?(@voters_count)
|
|
|
|
|
|
|
|
@voters_count = poll_votes.count
|
|
|
|
end
|
2018-11-19 21:50:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: poll_options
|
|
|
|
#
|
2019-05-13 23:37:21 +08:00
|
|
|
# id :bigint not null, primary key
|
|
|
|
# poll_id :bigint
|
2018-11-19 21:50:00 +08:00
|
|
|
# digest :string not null
|
|
|
|
# html :text not null
|
|
|
|
# anonymous_votes :integer
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_poll_options_on_poll_id (poll_id)
|
|
|
|
# index_poll_options_on_poll_id_and_digest (poll_id,digest) UNIQUE
|
|
|
|
#
|
2019-05-13 23:37:21 +08:00
|
|
|
# Foreign Keys
|
|
|
|
#
|
|
|
|
# fk_rails_... (poll_id => polls.id)
|
|
|
|
#
|