2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-02 17:41:57 +08:00
|
|
|
class CustomEmoji < ActiveRecord::Base
|
|
|
|
belongs_to :upload
|
2024-07-22 14:44:49 +08:00
|
|
|
belongs_to :user
|
2017-02-02 17:41:57 +08:00
|
|
|
|
2022-06-09 07:24:30 +08:00
|
|
|
has_many :upload_references, as: :target, dependent: :destroy
|
|
|
|
|
2017-02-02 17:41:57 +08:00
|
|
|
validates :name, presence: true, uniqueness: true
|
|
|
|
validates :upload_id, presence: true
|
2024-07-22 14:44:49 +08:00
|
|
|
validates :user_id, presence: true
|
|
|
|
|
|
|
|
before_validation :set_default_user_id, on: :create
|
2022-06-09 07:24:30 +08:00
|
|
|
|
|
|
|
after_save do
|
|
|
|
if saved_change_to_upload_id?
|
|
|
|
UploadReference.ensure_exist!(upload_ids: [self.upload_id], target: self)
|
|
|
|
end
|
|
|
|
end
|
2024-07-22 14:44:49 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_default_user_id
|
|
|
|
self.user_id ||= Discourse.system_user.id
|
|
|
|
end
|
2017-02-02 17:41:57 +08:00
|
|
|
end
|
2017-03-22 14:26:53 +08:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: custom_emojis
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# name :string not null
|
|
|
|
# upload_id :integer not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2020-04-28 18:29:39 +08:00
|
|
|
# group :string(20)
|
2024-07-22 14:44:49 +08:00
|
|
|
# user_id :integer default(-1), not null
|
2017-03-22 14:26:53 +08:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_custom_emojis_on_name (name) UNIQUE
|
|
|
|
#
|