class ExaminationBank < ApplicationRecord belongs_to :user belongs_to :sub_discipline has_many :tag_discipline_containers, as: :container, dependent: :destroy has_many :tag_disciplines, through: :tag_discipline_containers has_many :examination_items, -> {order(position: :asc)}, dependent: :destroy def apply? !public && ApplyAction.where(container_type: "ExaminationBank", container_id: id, status: 0).exists? end def question_count examination_items.size end def total_score examination_items.pluck(:score).sum end end