2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-05-23 22:48:32 -04:00
|
|
|
class PostReply < ActiveRecord::Base
|
2020-05-13 16:08:15 -04:00
|
|
|
# TODO(2020-01-17): remove
|
2020-01-17 11:24:49 -05:00
|
|
|
self.ignored_columns = %w{
|
|
|
|
reply_id
|
|
|
|
}
|
|
|
|
|
2013-05-23 22:48:32 -04:00
|
|
|
belongs_to :post
|
2020-01-17 11:24:49 -05:00
|
|
|
belongs_to :reply, foreign_key: :reply_post_id, class_name: 'Post'
|
2013-05-23 22:48:32 -04:00
|
|
|
|
2020-01-17 11:24:49 -05:00
|
|
|
validates_uniqueness_of :reply_post_id, scope: :post_id
|
2016-07-13 11:34:21 -04:00
|
|
|
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
|
2013-05-23 22:48:32 -04:00
|
|
|
end
|
|
|
|
|
2013-05-23 22:35:14 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: post_replies
|
|
|
|
#
|
2020-01-17 11:24:49 -05:00
|
|
|
# post_id :integer
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# reply_post_id :integer
|
2013-05-23 22:35:14 -04:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
2020-01-17 11:24:49 -05:00
|
|
|
# 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)
|
2013-05-23 22:35:14 -04:00
|
|
|
#
|