2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-18 03:28:44 -05:00
|
|
|
class PostReplyKey < ActiveRecord::Base
|
|
|
|
belongs_to :post
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
before_validation { self.reply_key ||= self.class.generate_reply_key }
|
|
|
|
|
2022-06-06 14:13:26 -05:00
|
|
|
validates :post_id, presence: true
|
2018-07-18 03:28:44 -05:00
|
|
|
validates :user_id, presence: true
|
|
|
|
validates :reply_key, presence: true
|
|
|
|
|
2019-01-09 19:56:03 -06:00
|
|
|
def reply_key
|
2023-01-09 06:20:10 -06:00
|
|
|
super&.delete("-")
|
2019-01-09 19:56:03 -06:00
|
|
|
end
|
|
|
|
|
2018-07-18 03:28:44 -05:00
|
|
|
def self.generate_reply_key
|
2019-01-09 19:56:03 -06:00
|
|
|
SecureRandom.hex(16)
|
2018-07-18 03:28:44 -05:00
|
|
|
end
|
|
|
|
end
|
2018-07-24 02:49:55 -05:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: post_reply_keys
|
|
|
|
#
|
2019-05-02 17:34:12 -05:00
|
|
|
# id :bigint not null, primary key
|
2018-07-24 02:49:55 -05:00
|
|
|
# user_id :integer not null
|
|
|
|
# post_id :integer not null
|
|
|
|
# reply_key :uuid not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_post_reply_keys_on_reply_key (reply_key) UNIQUE
|
|
|
|
# index_post_reply_keys_on_user_id_and_post_id (user_id,post_id) UNIQUE
|
|
|
|
#
|