class Speaker < ApplicationRecord belongs_to :conference has_many :session_speakers, dependent: :destroy has_many :sessions, through: :session_speakers validates :ref_id, uniqueness: { scope: :conference_id } after_update :notify_if_changed def to_param ref_id end private def notify_if_changed return if new_record? return unless saved_changes.present? ActiveSupport::Notifications.instrument("speaker.updated", record: self, changes: saved_changes) end end