class Activity < ApplicationRecord include Auditable belongs_to :user, optional: true belongs_to :organization belongs_to :contact, optional: true belongs_to :opportunity, optional: true validates :activity_type, inclusion: { in: Catalog::ACTIVITY_TYPES.keys } validates :subject, :happened_at, presence: true scope :recent_first, -> { order(happened_at: :desc, id: :desc) } scope :chronological, -> { order(happened_at: :asc, id: :asc) } def activity_type_label Catalog.label_for(Catalog::ACTIVITY_TYPES, activity_type) end end