mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 22:14:03 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
36 lines
758 B
Ruby
36 lines
758 B
Ruby
# frozen_string_literal: true
|
|
|
|
class PostReply < ActiveRecord::Base
|
|
belongs_to :post
|
|
belongs_to :reply, class_name: 'Post'
|
|
|
|
validates_uniqueness_of :reply_id, scope: :post_id
|
|
validate :ensure_same_topic
|
|
|
|
private
|
|
|
|
def ensure_same_topic
|
|
if post.topic_id != reply.topic_id
|
|
self.errors.add(
|
|
:base,
|
|
I18n.t("activerecord.errors.models.post_reply.base.different_topic")
|
|
)
|
|
end
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: post_replies
|
|
#
|
|
# post_id :integer
|
|
# reply_id :integer
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_post_replies_on_post_id_and_reply_id (post_id,reply_id) UNIQUE
|
|
# index_post_replies_on_reply_id (reply_id)
|
|
#
|