2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-18 04:28:44 -04:00
|
|
|
class PostReplyKey < ActiveRecord::Base
|
|
|
|
belongs_to :post
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
before_validation { self.reply_key ||= self.class.generate_reply_key }
|
|
|
|
|
2022-06-06 15:13:26 -04:00
|
|
|
validates :post_id, presence: true
|
2018-07-18 04:28:44 -04:00
|
|
|
validates :user_id, presence: true
|
|
|
|
validates :reply_key, presence: true
|
|
|
|
|
2019-01-09 20:56:03 -05:00
|
|
|
def reply_key
|
|
|
|
super&.delete("-")
|
|
|
|
end
|
|
|
|
|
2018-07-18 04:28:44 -04:00
|
|
|
def self.generate_reply_key
|
2019-01-09 20:56:03 -05:00
|
|
|
SecureRandom.hex(16)
|
2018-07-18 04:28:44 -04:00
|
|
|
end
|
|
|
|
end
|
2018-07-24 03:49:55 -04:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: post_reply_keys
|
|
|
|
#
|
2019-05-02 18:34:12 -04:00
|
|
|
# id :bigint not null, primary key
|
2018-07-24 03:49:55 -04: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
|
|
|
|
#
|