2013-05-23 22:48:32 -04:00
|
|
|
class PostReply < ActiveRecord::Base
|
|
|
|
belongs_to :post
|
|
|
|
belongs_to :reply, class_name: 'Post'
|
|
|
|
|
|
|
|
validates_uniqueness_of :reply_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
|
|
|
|
#
|
|
|
|
# post_id :integer
|
|
|
|
# reply_id :integer
|
2014-08-27 01:19:25 -04:00
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2013-05-23 22:35:14 -04:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_post_replies_on_post_id_and_reply_id (post_id,reply_id) UNIQUE
|
|
|
|
#
|