discourse/app/models/post_reply.rb
Jarek Radosz 8baf4d5d4c
DEV: Enable Style/RedundantSelf rubocop rule (#40098)
(to be enabled in the shared config)
2026-05-19 19:27:45 +02:00

32 lines
797 B
Ruby
Vendored

# frozen_string_literal: true
class PostReply < ActiveRecord::Base
belongs_to :post
belongs_to :reply, foreign_key: :reply_post_id, class_name: "Post"
validates :reply_post_id, uniqueness: { scope: :post_id }
validate :ensure_same_topic
private
def ensure_same_topic
if post.topic_id != reply.topic_id
errors.add(:base, I18n.t("activerecord.errors.models.post_reply.base.different_topic"))
end
end
end
# == Schema Information
#
# Table name: post_replies
#
# created_at :datetime not null
# updated_at :datetime not null
# post_id :integer
# reply_post_id :integer
#
# Indexes
#
# index_post_replies_on_post_id_and_reply_post_id (post_id,reply_post_id) UNIQUE
# index_post_replies_on_reply_post_id (reply_post_id)
#