class GtaskBank < ApplicationRecord
  belongs_to :user
  belongs_to :graduation_task, optional: true
  belongs_to :course_list, optional: true

  has_many :attachments, as: :container, dependent: :destroy
  has_many :graduation_tasks, dependent: :nullify

  scope :myself, ->(user_id) { where(user_id: user_id)}
  scope :is_public, -> { where(:is_public => true) }

  validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
  validates :description, length: { maximum: 5000, too_long: "不能超过5000个字符" }
end
