class ExerciseBank < ApplicationRecord # container_type: Poll 问卷; Exercise试卷 belongs_to :user belongs_to :course_list has_many :exercise_bank_questions, :dependent => :destroy has_many :polls, dependent: :nullify has_many :exercises, dependent: :nullify # def course_list_name # self.course_list ? self.course_list.name : "" # end # scope :myself, -> (user_id){where(user_id: user_id)} scope :find_by_container, lambda { |id,type| where(container_id: id,container_type:type)} scope :find_by_c_type, lambda { |keywords| where(container_type: keywords) unless keywords.blank?} scope :public_exercises, -> {where(is_public: true)} scope :exercise_bank_search, lambda { |keywords| where("name LIKE ?", "%#{keywords}%") unless keywords.blank?} end