class Page < ApplicationRecord
  belongs_to :report, touch: true
  has_many :elements, dependent: :destroy

  has_rich_text :comment

  before_validation :set_position

  private
  def set_position
    self.position ||= (report.pages.pluck(:position).max || 0) + 1
  end
end
