mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
22 lines
555 B
Ruby
22 lines
555 B
Ruby
class SailorsLogNotificationPreference < ApplicationRecord
|
|
before_validation :ensure_sailors_log_exists
|
|
|
|
belongs_to :sailors_log,
|
|
class_name: "SailorsLog",
|
|
foreign_key: :slack_uid,
|
|
primary_key: :slack_uid
|
|
|
|
validates :slack_uid, uniqueness: {
|
|
scope: :slack_channel_id,
|
|
message: "already has a notification preference for this channel"
|
|
}
|
|
|
|
private
|
|
|
|
def ensure_sailors_log_exists
|
|
return if sailors_log.present?
|
|
|
|
self.sailors_log = SailorsLog.find_or_create_by(slack_uid: slack_uid)
|
|
end
|
|
end
|