class PostTagSection < ApplicationRecord
  self.primary_key = :post_id, :tag_id, :begin_ms

  belongs_to :post
  belongs_to :tag

  belongs_to :post_tag, -> { kept }, foreign_key: [:post_id, :tag_id],
                                     primary_key: [:post_id, :tag_id],
                                     inverse_of: :sections,
                                     optional: true

  validates :post_id, presence: true
  validates :tag_id, presence: true

  validates :begin_ms, presence: true,
                       numericality: { only_integer: true, greater_than_or_equal_to: 0 }

  validates :end_ms, numericality: { only_integer: true, greater_than: :begin_ms },
                     allow_nil: true
end
