class Inform < ApplicationRecord
  belongs_to :container, polymorphic: true, optional: true
  belongs_to :user, optional: true

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

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

  def next_inform
    Inform.find_by(position: self.position+1, container_id: self.container_id, container_type: self.container_type)
  end

  def  last_inform
    Inform.find_by(position: self.position-1, container_id: self.container_id, container_type: self.container_type)
  end

end
